Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
312 views
in Technique[技术] by (71.8m points)

android - 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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...