Reputation: 447
I'm using ListView to show all records from the database. Each row of the list has an additional checkbox. I want to make a button that when pressed will delete all checked records. However, when I'm iterating through the list and trying to get the reference to the rows with getChildAt(index), I can reach only 3 initial entries because the rest of them are hidden and in the application I have to use scrollbar for them.
How can I reach them that something like that worked fine:
for( int i = 0; i < taskList.size(); i++ ){
View row = list.getChildAt(i);
CheckBox checkBox = (CheckBox)row.findViewById(R.id.checkbox)
}
Upvotes: 0
Views: 85
Reputation: 33741
Instead of iterating through the views, have the data that's backing the adapter have a field/variable in it that keeps track of the checked state. then, simply iterate through your collection and remove all of the ones that are checked. then notifydatasetchanged
Upvotes: 2