Android: Wrong item checked when filtering listview

前端 未结 3 830
挽巷
挽巷 2021-01-06 13:25

I\'m suffering from the same issue as this question: Wrong item checked when filtering ListView in android

As suggested in the above question, I have an Hashset hold

3条回答
  •  甜味超标
    2021-01-06 13:38

    Solved the issue. As suggested in the question I added to mine, when you populate the checkboxes, the other List/Hashset should determine whether to mark item as checked or not.

    Using my code:

    //first you will need to get the current item ID
    String bookmarkID = cursor.getString(0);
    
    //Then, check if the current ID is in the selectedIds hash/list
    //If true - mark current item view as checked, else - uncheck.
            CheckedTextView markedItem = (CheckedTextView) row.findViewById(R.id.btitle);
            if (selectedIds.contains(new String(bookmarkID))) {
                markedItem.setChecked(true);
    
            } else {
                markedItem.setChecked(false);
    }
    

    Really hope this will help anyone! :)

提交回复
热议问题