过滤后的ListView onItemClick在原来的位置返回项目位置、项目、ListView、onItemClick

2023-09-12 22:57:32 作者:用微笑伪装自己的悲伤

我有一个自定义行的列表视图被填充从定制 BaseAdaptor 。在点击任一行,我打开一个新的活动。 一切工作正常,直到我添加的过滤功能,这个名单。当我搜索列表,然后单击一个项目,它不会打开与筛选的结果相关联的活动。它开辟了在原始列表中该位置与该项目有关的活动。

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.

例如。 - 原始列表:AA,BA,CC,DA,ED,FF

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

搜索:'A' 筛选结果:AA,BA,DA

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

但是,当我点击项目 DA 它开辟了活动的 CC 。刺激性极强。我已经叫 notifyDataSetChanged()适配器上。

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

我一直坚持这个问题一段时间。我真的不知道如何解决这个问题。 我没有张贴code,因为它是一大堆的code,我真的不希望把这里的一切。

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.

如果有人可以给我如何从筛选列表中的项目的想法。它会B非常好。

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!

推荐答案

感谢回答所有,但我发现这个问题。

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!

要开始我的新的活动,我正在从自定义适配器的项目位置,而不会覆盖的getItem()函数。

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);

我overrid功能

I overrid the function

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

和瞧!得到了正确的活动开幕。 ( facepalm 的,我知道..) 谢谢您的回答呢!

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