在过滤的ListView android的错时检查项目 [英] Wrong item checked when filtering ListView in android

查看:95
本文介绍了在过滤的ListView android的错时检查项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多种选择项一个ListView,其中有些是从一开始就使用检查

I have a ListView with multiple choice entries where some are checked from the beginning using

setItemChecked(position, true);

我结合这与过滤选项

I combine this with the filtering option

setTextFilterEnabled(true)

所以很容易找到列表中的特定条目。

so it's easy to find a specific entry in the list.

的问题是,当我过滤列表中的条目切换在列表视图中的位置。就拿三个条目:'A','B'何'C'事先检查'C'(即3位在列表中的条目)。当我在键盘上输入C,则仅显示C条目(如预期)。现在C不再被选中,因为该条目已经从检查位置3移动到列表中的选中位置1

The problem is that when I filter the list the entries switch position in the list view. Take for example three entries: 'A', 'B' and 'C' where 'C' is checked beforehand (i.e. the entry at position 3 in the list). When I type a 'C' on the keyboard, only the 'C' entry is displayed (as intended). Now 'C' is not checked anymore, since the entry has moved from the checked position 3 to the unchecked position 1 in the list.

此行​​为将导致在应用中的一些不是很受欢迎的效果。是否有移动与过滤的选择,即选中状态结合到条目,而不是在该列表的初始位置的方法吗?或者,我需要找到一个新的途径?

This behavior leads to some not very welcome effects in the app. Is there a way to "move the selection with the filtering", i.e. bind the checked state to the entry and not to its initial position in the list? Or do I need to find a new approach?

谢谢,

莱纳斯

推荐答案

保持选定的项目清单,每当清单重新填充检查如果 ID (不位置)在列表中存在,并作为选择设置

Maintain a list of the selected items, and whenever the list is repopulated check if that id (not position) exists in the list, and set as selected.

这篇关于在过滤的ListView android的错时检查项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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