select all check box in android listview -
in application, tried create list multiple check boxes.
for tried 1 listview android.r.layout.simple_list_item_multiple_choice multiple choice in listview.
my listview in xml as,..
<listview android:id="@android:id/list" android:layout_width="match_parent" android:layout_height="468dp" android:choicemode="multiplechoice" android:divider="#b5b5b5" android:dividerheight="1dp" > and use checkbox select/deselect checkbox in listview as
<checkbox android:id="@+id/select_all" android:layout_width="120dp" android:layout_height="wrap_content" android:layout_column="2" android:textsize="18dp" android:text="select all" /> and java code as,..
selectall.setonclicklistener(new onclicklistener() { public void onclick(view v) { // todo auto-generated method stub int size = 0; boolean ischecked = selectall.ischecked(); if (ischecked == true) { size = getlistview().getcount(); (int = 0; <= size; i++) l1.setitemchecked(i, true); } else if(ischecked==false) { size = getlistview().getcount(); (int = 0; <= size; i++) l1.setitemchecked(i, false); } } }); here have assigned l1 listview. select check box working select/deselect check boxes in listview.
but, if deselect 1 of item after clicking select check box, not un-checking..
and if select check boxes in list manually means, select checkbox needs checked automatically..
i used following codes listadapter
arrayadapter<string> adapter1 = new arrayadapter<string> (this,android.r.layout.simple_list_item_multiple_choice,list); setlistadapter(adapter1); l1=getlistview(); i'm trying achieve solution..
you use hashmap or list of theobjectrow keep track of sheckbox checked boolean.
then when click on checkall update boolean in list true , youradapter.notifydatasetchanged();
of course in adapter (baseadapter example) use hashmap/list in getview init cells.
if(list.get(position).ischecked()){ cellholder.checkbox.setchecked(true); } else{ cellholder.checkbox.setchecked(false); } all boolean @ true checkbox ll checked (the same logic goes uncheck)
hope luck
Comments
Post a Comment