Click here to Skip to main content
15,887,335 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
I want to show alertbox of particular selected checkbox using function this is my code
Java
call.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ListView mainListView = mDrawerList;
                checkbox = (CheckBox) mainListView.getChildAt(0).findViewById(R.id.checkBox1);
                checkbox1 = (CheckBox) mainListView.getChildAt(1).findViewById(R.id.checkBox1);
                checkbox2 = (CheckBox) mainListView.getChildAt(2).findViewById(R.id.checkBox1);
                checkbox3 = (CheckBox) mainListView.getChildAt(3).findViewById(R.id.checkBox1);
                for (int x = 0; x < mainListView.getChildCount(); x++) {
 
                    if (checkbox.isChecked()) {
                        getMain();
 
                    }
 
                    else if (checkbox1.isChecked()) {
                        second();
 
                    }
                    else if (checkbox2.isChecked()) {
                        third();
 
                    }
                    else if (checkbox3.isChecked()) {
                        fourth();
 
                    } else {
                        getMain();
 
                    }
                }
            }
        });


but there is 4 alertbox is displaying !!

What I have tried:

But when i calling single function without using checkbox

Java
call.setOnClickListener(new OnClickListener(){
        public void onClick(View v) {
        // TODO Auto-generated method stub
            getMain();
        }

    });" 

Now only one alertbox is there
Posted
Updated 16-Mar-16 0:20am

1 solution

Because in every case you are calling: findViewById(R.id.checkBox1)
 
Share this answer
 
Comments
C0DE_007 17-Mar-16 13:48pm    
yes sir ??

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900