android - Select All items of a ListView (custom row with checkbox in it) -


what have: have listview custom rows, having checkbox & 2 textviews in each row. have button "select all".

what want: want when click button, checkbox in listview checked/unchecked.

what problem: in onclick of "select all" button. doing this:

public void onclickselectallbutton(view view) {     listview l = getlistview();     int count = l.getcount();     for(int i=0; i<count; ++i)      {        viewgroup row = (viewgroup)l.getchildat(i);        checkbox check = (checkbox) row.findviewbyid(r.id.checkboxid);        check.setchecked(true); // true select , false unselect etc..     } } 

here l.getchildat(i) giving me visible items only. , when index goes out of visible items, problem occurs. want check checkbox in list, not visible ones.

it occur, because listview adapter reuses views. way trying incorrect. don't think ever should access listview rows through listview children.

introduce variable in activity, hold current state (boolean checkall). when user presses button, must set "checkall" true, , call notifydatasetchanged() (for arrayadapter), or requery() (for cursoradapter) on listview's adapter. in adapter's getview() method introduce check flag, if (checkall) {check check box}


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -