Question: I used **SparseBooleanArray** to get positions of checked listitems in a listView:

```
// lv is my listview
final SparseBooleanArray checkedItems = lv.getCheckedItemPositions();

```

This works fine when I check a list item. But when I unchecked an item from listview, its size didn't decrease. It remained as it was.

Let me explain what is happening:  

I firstly select 3 listitems and I get the size of *checkedItems* as 3. But when I uncheck one item from the list, its size doesn't change to 2. It is still 3.

What needs to be done? Kindly help me out. 

Stone

Answer: 
[`SparseBooleanArray`](http://developer.android.com/reference/android/util/SparseBooleanArray.html) maps integers to booleans. The `size()` method does not return the number of `true` items contained, it returns the number of items stored. Some of those items may be `false`.

If you want to know the number of items checked, you can iterate over the SparseBooleanArray, you can track the number of checked items by calling `isItemChecked()` when checked state changes, or if you are on API 11+ (Honeycomb) you can call `getCheckedItemCount()`.
The `SparseBooleanArray` does not contain the details of all the rows. The keys contain the index of the row and the value contains if that is checked. If one row was checked and then unchecked, the array will contain one entry for that row. So to deal with this you need to do the following:

1. Get the size by calling int `lSize = ObjectOfSparseBooleanArray.size()`.
2. Run a loop as `for(int i = 0; i < lSize; i++) {`
3. Get the row number `int lPos = ObjectOfSparseBooleanArray.keyAt(i);`
4. Get is the row is checked `boolean lIsChecked = ObjectOfSparseBooleanArray.get(lPos);`
5. Do your processing for the selected rows!