ListView绑定checkbox状态。

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6


在listView中使用checkBox,checkBox不会有作用如:

setListAdapter( new SimpleCursorAdapter( this, 
      R.layout.mylist, 
      data, 
      new String[] { Datenbank.DB_STATE, Datenbank.DB_NAME }, 
      new int[] { R.id.list_checkbox, R.id.list_text } 
    ) );

 

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout android:id="@+id/LinearLayout01" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
xmlns:android="http://schemas.android.com/apk/res/android" 
> 
 
<CheckBox android:text="" 
        android:id="@+id/list_checkbox" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:checked="false" 
        ></CheckBox> 
 
<TextView android:text="" 
        android:id="@+id/list_text" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        ></TextView> 
 
</LinearLayout>

 

数据库的值在里面全都是fouse,而数据库中本身的状态如果是true,但是这个按钮还是false。

那么现在你可以这么用:

public class MyActivity extends ListActivity { 
 
    MyAdapter mListAdapter; 
 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
        Cursor myCur = null; 
 
        myCur = do_stuff_here_to_obtain_a_cursor_of_query_results(); 
 
        mListAdapter = new MyAdapter(MyActivity.this, myCur); 
        setListAdapter(mListAdapter); 
    } 
 
 
    private class MyAdapter extends ResourceCursorAdapter { 
 
        public MyAdapter(Context context, Cursor cur) { 
            super(context, R.layout.mylist, cur); 
        } 
 
        @Override 
        public View newView(Context context, Cursor cur, ViewGroup parent) { 
            LayoutInflater li = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
            return li.inflate(R.layout.mylist, parent, false); 
        } 
 
        @Override 
        public void bindView(View view, Context context, Cursor cur) { 
            TextView tvListText = (TextView)view.findViewById(R.id.list_text); 
            CheckBox cbListCheck = (CheckBox)view.findViewById(R.id.list_checkbox); 
 
            tvListText.setText(cur.getString(cur.getColumnIndex(Datenbank.DB_NAME))); 
            cbListCheck.setChecked((cur.getInt(cur.getColumnIndex(Datenbank.DB_STATE))==0? false:true)))); 
        } 
    } 
}

 

或者

SimpleCursorAdapter cursorAdapter = new SimpleCursorAdapter(/* ur stuff */); 
cursorAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() { 
    public boolean setViewValue(View view, Cursor cursor, int columnIndex) { 
        if(columnIndex == 1) { 
                CheckBox cb = (CheckBox) view; 
                cb.setChecked(cursor.getInt(1) > 0); 
                return true; 
        } 
        return false; 
    } 
});

 

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6

“ListView绑定checkbox状态。” 的相关文章

thinkphp3.2怎么使用立即跳转功能 - 编程语言

本篇内容主要讲解“thinkphp3.2怎么使用立即跳转功能”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“thinkphp3.2怎么使用立即跳转功能”吧! 在ThinkPHP框架中,立即跳转功能...

进程管理

将命令放入后台:mv file1 p2 & 将当前的作业放到后台:ctrl z 观察后台作业状态:jobs -l 将后台作业拿到前台:fg %2477(job num) 杀死进程 1.正常杀:kill -15 2487 2.强杀:kill -9 24...

双显示器

首先设置主显,根据情况试试,第一个不行就试第二个: sudo xrandr --output DVI1 --primary sudo xrandr --output VGA1 --primary 然后如果鼠标移动不正常: 系统->首选项->显示器...

UVa 10340 All in All (字符串处理&编程技巧)

10340 - All in AllTime limit: 3.000 secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=457&page=show_pr...

如何在vscode设置php运行环境 - 编程语言

本文小编为大家详细介绍“如何在vscode设置php运行环境”,内容详细,步骤清晰,细节处理妥当,希望这篇“如何在vscode设置php运行环境”文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习新知识吧。 安装PHP插件首先,...

提示信息控件AlertDialog对话框怎么使用 - 开发技术

这篇文章主要介绍“提示信息控件AlertDialog对话框怎么使用”,在日常操作中,相信很多人在提示信息控件AlertDialog对话框怎么使用问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”提示信息控件AlertDialog对话框怎么使...