过滤后的 ListView onItemClick 返回原始位置的 Item [英] Filtered ListView onItemClick returns Item at original position

查看:24
本文介绍了过滤后的 ListView onItemClick 返回原始位置的 Item的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个列表视图,其中包含从自定义 BaseAdaptor 填充的自定义行.单击任意行,我会打开一个新的 Activity.一切正常,直到我将过滤器功能添加到此列表中.当我搜索列表然后单击一个项目时,它不会打开与过滤结果关联的活动.它会打开一个与原始列表中该位置的项目相关的活动.

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.

我被这个问题困扰了一段时间.我真的不知道如何解决它.我没有发布代码,因为它是一大堆代码,我真的不想把所有东西都放在这里.

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.

如果有人能告诉我如何从 FILTERED 列表中选择项目.. 那就太好了.

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

我覆盖了函数

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

这篇关于过滤后的 ListView onItemClick 返回原始位置的 Item的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆