我使用的是的ListView
有:
复选框
点击我可以用节约cursorPosition view.setTag(cursor.getPosition())
,我可以采取对检查项目采取必要的行动,但是当我向下滚动,我看到其他几个的CheckBox
检查(仅目测)。由于周围的工作我尝试设置描述来看,节约 CheckedBox
列表视图中的ID,然后遍历,看看复选框
由于需要检查显示。但观点似乎被重用,因为我向下滚动(相同观点IDS)。
我怎么只能显示实际检查的CheckBox
? code:
公共类MyViewBinder实现ViewBinder { 公共布尔setViewValue(查看视图,最后光标光标,诠释参数:columnIndex){ INT viewId = view.getId(); 开关(viewId){ 案例R.id.checkbox: view.setTag(cursor.getPosition()); 返回true; 案例R.id ..... ....... }
用于为:
mySimpleCursorAdapter.setViewBinder(myViewBinder);
解决方案我没有与ViewBinder接口太多经验,但你有没有考虑使用 setChoiceMode()
在列表视图(参考)?你可以让机器人添加复选框将其设置为 CHOICE_MODE_MULTIPLE 您。你不应该需要担心维护检查的项目这种方式。
API演示例子。
I'm using a ListView
which has:
CheckBox
click
I can save the cursorPosition by using view.setTag(cursor.getPosition())
and I can take necessary action on the checked item but when I scroll down, I see several other CheckBoxes
checked(visual only).
As a work around I tried setting the view description, saving CheckedBox
view ids in list and then iterate to see if CheckBox
needs to be shown as checked. But views appear to be reused as I scroll down(same view ids).
How can I only show the actual checked CheckBoxes
? Code:
public class MyViewBinder implements ViewBinder {
public boolean setViewValue(View view, final Cursor cursor, int columnIndex) {
int viewId = view.getId();
switch (viewId) {
case R.id.checkbox:
view.setTag(cursor.getPosition());
return true;
case R.id.....
.......
}
Used as:
mySimpleCursorAdapter.setViewBinder(myViewBinder);
解决方案
I don't have too much experience with the ViewBinder Interface but have you considered using setChoiceMode()
on the listview (API reference)? You can set it to CHOICE_MODE_MULTIPLE so that android adds the checkboxes for you. You shouldn't need to worry about maintaining the checked items this way.
API Demo example.