http://blog.csdn.net/elinavampire/article/details/42869015
1.checkbox可以点击,但是listview的item无法点击
2.无法获得checkbox被点击的是哪一行
1,设置 checkbox无法响应点击事件
[html] view plaincopy
- android:clickable="false"
- android:focusable="false"
- android:focusableInTouchMode="false"
2.适配器中声明一个值用来控制checkbox的选中情况
[java] view plaincopy
- private static HashMap<Integer,Boolean> isSelected;
[java] view plaincopy
- public static HashMap<Integer,Boolean> getIsSelected() {
- return isSelected;
- }
- public static void setIsSelected(HashMap<Integer,Boolean> isSelected) {
- MyDocShowAdapter.isSelected = isSelected;
- }
[java] view plaincopy
- isSelected = new HashMap<Integer, Boolean>();
- for(int i=0; i<list.size();i++) {
- getIsSelected().put(i,false);
- }
3.根据item的点击情况,给checkbox赋值
[java] view plaincopy
- mListView.setOnItemClickListener(new OnItemClickListener() {
- @Override
- public void onItemClick(AdapterView<?> parent, View view,
- int position, long id) {
- ViewHolder holder = (ViewHolder) view.getTag();
- holder.mCheckBox.toggle();
- MyDocShowAdapter.getIsSelected().put(position, holder.mCheckBox.isChecked());
- }
- });
今天就到这,有问题请留言,多交流
时间: 2024-10-05 23:26:47