I'm trying to implement removing chosen TextViews
from my ListView
.
The one way to do this according to android dev reference is by using SparseBooleanArray
. The problem is, I don't understand the logic behing this array and every time I call the getCheckedItemPositions()
, method returns the empty array.
Here is the sample of my code:
List<Record> records = new RecordDAO(this).findAll(); //gets all records saved in ListView from database
SparseBooleanArray checkedPositions = recordListView.getCheckedItemPositions();
for(int i = 0; i < records.size(); i++){
if(checkedPositions.valueAt(i)){
System.out.println("chosen at pos: " + i);
}
}
I choose the last 2 TextViews press button
and the output is:
I/System.out: chosen at pos: 0
I/System.out: chosen at pos: 1
- How do I properly solve my problem?
- Can anyone explain me how does the SparseBooleanArray working?