简体   繁体   English

当textfilter时,Android ListView会获得列表项的正确位置

[英]Android listview get right position of list item when textfilter

I have a question about the listview. 我对列表视图有疑问。 I have a listview with textfilter enabled. 我有一个启用了textfilter的listview。 When I click a listitem without textfilter I get the position and I give it to the next activity which show the right text based on the position. 当我单击没有文本过滤器的列表项时,我得到了位置并将其交给下一个活动,该活动将根据位置显示正确的文本。 But when I use the text filter and click an item it the next activity shows me the wrong text, probably because the positions of the listitems changed. 但是,当我使用文本过滤器并单击一个项目时,下一个活动将向我显示错误的文本,这可能是因为列表项的位置发生了变化。 Does somebody have a solution for this problem, eg not working with positions but another reference from a list item? 是否有人对此问题有解决方案,例如不使用职位而是使用列表项中的另一个引用? I looked everywhere but couldn't find a solution. 我到处看,但找不到解决方案。

Thanks in advance 提前致谢

You can get the correct item at position from the listAdapter directly. 您可以直接从listAdapter获得正确的position It contains only the current items displayed in the list. 它仅包含列表中显示的当前项目。

listAdapter .getItem(position);

Reference : onItemClick gives index/ position of item on visible page ... not actual index of the item in list ..problem on enabling setTextFilterEnabled .. android 参考: onItemClick给出项目在可见页面上的索引/位置...而不是列表中该项目的实际索引。.在启用setTextFilterEnabled ..android时出现问题

If there is something wrong with position , you can change from id to position . 如果position ,则可以从id更改为position When list is filtered the position in onClick event is the new position in filtered list not the old one. 当过滤列表中的positiononClick事件是在过滤列表中不老的一个新的位置。 Normal, id is the order of your item in input data 正常, id是商品在输入数据中的顺序

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM