views:

67

answers:

1

I have a multiselection listview in my android app. What I need to know is how many items on that list I have selectet.

A: 

I found a solution. getCheckedItemPositions() will create a SparceBooleanArray. So it is just to count the elements which are true in that array.

Eksample:

int counter = 0; for(int i = 0; i < theArray.size(); i++){ if(theListView.getCheckedItemPositions().get(i)) counter ++; }

IronMonkey
You could also use: `theListView.getCheckedItemIds().size();` Not sure if this will be faster (depends on internal implementation), but it might be a little clearer to other people looking at the code.
Grant Peters
but the array created by getChekItemIds() does not get smaller when you uncheck an item.
IronMonkey