0

This is a follow up question to this question:

Retrieving the selected items from a multi-select ListView

I'm using a ListView with mode CHOICE_MODE_MULTIPLE_MODAL.

Is there a way to get the indexes of all checked Items ? In the question I posted above, there's a suggestion to use the method getCheckedItemPositions(), but I don't want to iterate over the entire list and check if it returns true so this is not what I need. I want to do something like this (pseudo code):

int[] checkedPositions = list.getCheckedIndexes();
for(int index : checkedPositions)
{
   list.remove(index);
}

Is there a way to do something like that?

Community
  • 1
  • 1
CodeMonkey
  • 11,196
  • 30
  • 112
  • 203
  • possible duplicate of [How to get all checked items from a ListView?](http://stackoverflow.com/questions/4831918/how-to-get-all-checked-items-from-a-listview) – nkorth Jul 02 '15 at 14:26

2 Answers2

0

It may use less code if such a method exists to return an array of checked items, but that method would likely use the same time complexity as just iterating yourself.

  • Not necessarily.. they might maintain a list while checking and unchecking list items. I can do it myself but just to know if they might have something like that already implemented. – CodeMonkey Jul 03 '15 at 16:38
0

Try getCheckedItemIds as mentioned in the documentation :

Returns the set of checked items ids.

To make it works correctly , in the adapter getItemId make it returns the position of the item

Fouad Wahabi
  • 804
  • 7
  • 16