如何使用复选框列表视图 [英] How to use checkbox in listview

查看:122
本文介绍了如何使用复选框列表视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用一个CheckBox ListView中。
我的适配器如下:

I use a CheckBox in ListView. My adapter as below:

@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewTag viewTag;
if(convertView == null) {
convertView = myInflater.inflate(R.layout.row, null);
viewTag = new ViewTag((CheckBox)convertView.findViewById(R.id.row_check));
convertView.setTag(viewTag);
}
else {
viewTag = (ViewTag) convertView.getTag();
}
}
class ViewTag {
CheckBox cbx;
public ViewTag(CheckBox cb) {
this.cbx = cb;
}
}

第一:
在ListActivity,我试着点击一个按钮,设置检查所有项目。
怎么做?
第二:
在ListActivity,如何让这些被检查的项目?

First: In ListActivity, I try to click a button to set all items checked. How to do it? Second: In ListActivity, how to get the items which were checked?

推荐答案

有很多实现这个方法,最简单的方法是创建一个布尔数组,以保持每行的状态,检查设置状态,从这个数组。要获得所有检查的项目只需检查相同的数组项的值。

There are many approaches to achieve this, simplest method is create a boolean array to keep state of each row, and set state of check from this array. To get all checked items simply check the same array item value.

这篇关于如何使用复选框列表视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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