Returning values from multiple selection ListView

前端 未结 4 831
一个人的身影
一个人的身影 2021-02-08 14:25

Edit: Okay, I found a solution. Don\'t know that it\'s the proper solution, but it does work correctly. Added to the code below.

I\'m trying to allow a user to select a

4条回答
  •  渐次进展
    2021-02-08 15:08

    I know you found a solution that works for you, but the cleaner and simpler solution that will probably work most of the time is this (I want to persist all the ids of the elements selected):

    (in my ListActivity):

    SparseBooleanArray selectedPos = getListView()
            .getCheckedItemPositions();
    
    ListAdapter lAdapter = getListAdapter();
    List ids = new ArrayList();
    for (int i = 0; i < lAdapter.getCount(); i++) {
        if (selectedPos.get(i)) {
            ids.add(lAdapter.getItemId(i));
        }
    }
    

提交回复
热议问题