Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filtered ListView onItemClick returns Item at original position

I have a listview with custom rows being populated from an custom BaseAdaptor. On click of any row, I open a new Activity. Everything was working fine until I added the filter functionality to this list. When I search the list and THEN click on an Item, it doesn't open the activity associated with the filtered results. It opens up an Activity related to the Item at that position in Original list.

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

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

But when I click on item DA it opens up the Activity for CC. Extremely irritating. I have called notifyDataSetChanged() on the adapter.

I've been stuck with this problem for sometime. I really dont know how to solve it. I didnt post the code because it's a whole lot of code and I really dont want to put everything here.

If someone can give me an idea of how to select the Item from the FILTERED list.. It'd b great.

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

like image 249
Sudhanshu Avatar asked Jan 28 '13 12:01

Sudhanshu


1 Answers

Thanks for replying all but I found the problem.

I hope this helps another person. With something this basic, it sometimes gets hard to find the error and we resort to much complicated ways!

To start my new activity, I was taking the item position from the custom Adaptor without overriding the getItem() function.

Object obj = myListAdapter.getItem(position);

I overrid the function

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

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

like image 164
Sudhanshu Avatar answered Sep 21 '22 22:09

Sudhanshu