ViewBinder setViewValue的ListView项导致多个复选框选中 [英] ViewBinder setViewValue for ListView item leads to multiple CheckBoxes checked

查看:226
本文介绍了ViewBinder setViewValue的ListView项导致多个复选框选中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是的ListView 有:


  1. 列表项点击

  2. 复选框点击

我可以用节约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 您。你不应该需要担心维护检查的项目这种方式。

<一个href=\"http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/List11.html\"相对=nofollow> API演示例子。

I'm using a ListView which has:

  1. list item click
  2. 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.

这篇关于ViewBinder setViewValue的ListView项导致多个复选框选中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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