如何在Android应用程序过滤列表视图后,获得正确的位置

问题描述:

在我的应用程序,当用户键入的东西在搜索框,然后列表被过滤,但列表项目的位置得到改变。并且由于当用户点击一个列表项这个变化的位置,会导致不必要的活动。因为我已经根据自己的位置设置事件列表项。是否有甚至越来越筛选列表后保持相同的列表项/行的任何参数?

In my app, when a user types something in a search box then a list gets filtered but the position of the list items gets changed. And due to this changed position when the user clicks on a list item, it results in unwanted activity. Because I have set events to the list items according to their position. Is there any parameter of the list items/row which remains same even after getting the list filtered?

您只需保持在动态数组中的Andr​​oid ....

使用 textWatcher 你刚刚从列表(不是的ListView $ C $ RemoveElements C>),如 mList.removeAllElements(); 并添加列表过滤元素,如 mList.addElement(元素) mAdapter.notifyDataSetChanged();

Using textWatcher You just RemoveElements from List(not ListView) like mList.removeAllElements(); and add filtered elements in List like mList.addElement(element) and mAdapter.notifyDataSetChanged();