Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have make a checkbox in each check it call a function

Java
call.setOnClickListener(new View.OnClickListener() {
           @Override
           public void onClick(View view) {
               checkbox = (CheckBox) findViewById(R.id.checkBox1);
               ListView mainListView = mDrawerList;
               checkbox = (CheckBox) mainListView.getChildAt(0);
               checkbox = (CheckBox) mainListView.getChildAt(1);
               checkbox = (CheckBox) mainListView.getChildAt(2);
               checkbox = (CheckBox) mainListView.getChildAt(3);
               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()) {
                       forth();

                   } else {
                       getMain();

                   }
               }
           }
       });


This is my DrawlerList.xml

XML
<CheckBox
    android:id="@+id/checkBox1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text=""
    android:layout_centerVertical="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true" />

<TextView
    android:id="@+id/title"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_toRightOf="@id/checkBox1"
    android:minHeight="?android:attr/listPreferredItemHeightSmall"
    android:textAppearance="?android:attr/textAppearanceListItemSmall"
    android:textColor="@color/list_item_title"
    android:gravity="center_vertical"
    android:paddingRight="40dp"/>


And in string.xml i set my items name

XML
<!-- Nav Drawer Menu Items -->
   <string-array name="nav_drawer_items">
       <item>Home</item>
       <item>Second</item>
       <item>Third</item>
       <item>Forth</item>
   </string-array>


But when i clicking only one checkbox but it displaying all function alertbox also

What I have tried:

When i try to call only one function

call.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
getMain(); // Now only one alert box is there
}
});
Posted
Updated 17-Mar-16 3:34am

1 solution

This is just a repost of Alertdialog box getting from every function[^], where I already told you what was wrong with your code. And what you have posted above is worse than what you started with. Please go back to the original and look again at what I told you.
 
Share this answer
 
Comments
C0DE_007 17-Mar-16 13:09pm    
But sir what should i do i can't remove findViewById(R.id.checkBox1)
C0DE_007 17-Mar-16 13:14pm    
when i am trying to remove findViewById(R.id.checkBox1) app is crashing
Richard MacCutchan 17-Mar-16 13:26pm    
Rather than just throwing random statements about, go back to your previous question (as I suggested above), read my comment carefully, and look at the actual code you have written. Can you see anything wrong with the names of the checkboxes you are trying to capture?
C0DE_007 17-Mar-16 14:09pm    
checkbox = (CheckBox) mainListView.getChildAt(0);
checkbox1 = (CheckBox) mainListView.getChildAt(1);
checkbox2 = (CheckBox) mainListView.getChildAt(2);
checkbox3 = (CheckBox) mainListView.getChildAt(3);
C0DE_007 17-Mar-16 14:11pm    
Is this is right ?

for (int x = 0; x < mainListView.getChildCount(); x++) {
checkbox = (CheckBox) mainListView.getChildAt(x).findViewById(R.id.checkBox1);
if (checkbox.isChecked() ) {
getFood();
}
checkbox1 = (CheckBox) mainListView.getChildAt(x).findViewById(R.id.checkBox1);
if (checkbox1.isChecked()) {
Veg();
}
checkbox2 = (CheckBox) mainListView.getChildAt(x).findViewById(R.id.checkBox1);
if (checkbox2.isChecked()) {
NonVeg();
}
checkbox3 = (CheckBox) mainListView.getChildAt(x).findViewById(R.id.checkBox1);
if (checkbox3.isChecked()) {
Drinks();
} else {
getFood();

}
}

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