I am suffering from the same problem as this question: Invalid item checked while filtering ListView in android
As suggested in the previous question, I have a Hashset containing all the selected identifiers, but I cannot figure out how to use it when the cursor overflows the marked elements.
My problem is only cosmetic - for example:
- Facebook is in fifth position on the unfiltered list.
- The user performed a search for “face”, only “Facebook” will appear in the 1st position in the filtered list.
- The user checks Facebook as selected and returns to the unfiltered list.
- The item being checked is the first item on the list, not Facebook (position 5).
Note: Other than that, everything else works fine. For example, “delete” will delete the desired items because I use selectedIds for this (even if the marked items are wrong).
One click on a list item:
OnItemClickListener mOnItemClickListener = new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
Inside the cursor: - this is where the problem is.
This refills the checked items - the problem is that it does it by position (pos), and what was the correct position of the element in the filtered list is not its position in the unfiltered list, which leads to an erroneously marked element.
CheckedTextView markedItem = (CheckedTextView) row.findViewById(R.id.btitle); markedItem.setChecked(checkedStates.get(pos));
Would thank for any help!
android android-listview
Lior luz
source share