过滤列表视图并获得正确的onclick项 [英] Filtering list view and getting correct onclick item

查看:94
本文介绍了过滤列表视图并获得正确的onclick项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个列表视图,并且已经实现了过滤.

I have a list view and I've implemente filtering.

让我们说我有项目A,B和C.如果在过滤器框中键入B,则只会显示项目B,它是列表的位置0(在位置1之前).因此,当我调用onClick项时,我得到的id/位置0,将导致显示有关A而不是B的详细信息.

Lets say I have items A, B and C. If I type B in the filter box, only item B will be displayed and it is the position 0 of the list (before it was in position 1). So when I call the onClick item, I get the the id/position 0, which leads to displaying details about A instead of B.

这是onclick代码:

This is the onclick code:

ListView lv = getListView();
lv.setTextFilterEnabled(true);

lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {

    Poi poi = pois.get((int)id);
    goPOIDETAIL(poi);

}
});

id和position具有相同的值.

id and position have the same value.

有没有一种方法可以获取原始位置,或获取其他值来指示我单击的真实商品?

is there a way to get the original position, or get some other value indicating the real item that I clicked?

谢谢

推荐答案

我认为问题出在您管理过滤器的方式上.您应该不是从原始列表(或数组)中而是从已过滤的对象中获取具有选定ID的对象.

I think the problem is in the way you manage your filter. You should get the object with selected id not from the original List (or array) but from the filtered one.

我在博客.希望对您有帮助

这篇关于过滤列表视图并获得正确的onclick项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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