Filtered ListView onItemClick returns the item in its original position

I have a listview with custom strings populated from a custom BaseAdaptor . When I click on any line, I open a new Activity . Everything worked fine until I added filter functionality to this list. When I look at the list and THEN clicks on Item, it does not open the activity associated with the filtered results. It opens the action related to the item at this position in the Source List.

Eg. - Initial List: AA, BA, CC, DA, ED, FF

Search: 'A' Filtered Results: AA, BA, DA

But when I click on the DA element, it opens the Activity for CC . Extremely annoying. I typed notifyDataSetChanged() on the adapter.

I was once stuck with this problem. I really don't know how to solve this. I did not publish the code because it contains a lot of code, and I really do not want to post everything here.

If someone can give me an idea on how to select an item from the FILTERED list .. That would be great.

Thanks! Tell me if something else is needed to understand my question!

+6
source share
2 answers

Thanks for answering everything, but I found the problem.

Hope this helps another person. With something basic, it’s sometimes difficult to find a mistake, and we resort to complex paths!

To start my new activity, I took a position position from a user adapter without overriding the getItem () function.

 Object obj = myListAdapter.getItem(position); 

I overcame the function

 @Override public Object getItem(int position) { return myList.get(position); } 

and voila! got the right opening activity. (facepalm I know ..) Thanks for your answers anyway!

+13
source

This is because your CustomAdapter uses your first cursor, not your filtered one.

you can use this in your adapter definition:

 public Cursor swapCursor(Cursor c1) { super.swapCursor(c1); c = c1; notifyDataSetChanged(); return c; } 

and in your call is used

 YourCustomAdapter.swapCursor(FilteredCursor); 
0
source

All Articles