最近比较忙碌,我也不知道忙的什么东西,打算写的博客写了一半,还没写完,今天先扯一扯项目中遇到的一个问题,一方面防止以后遇到这个问题忘记如何解决,另一方面希望可以提供给遇到同样问题的朋友一个思路.
下面开始正题,在listview的item中使用checkbox,当你按照普通的listview的用法使用时,你会遇到下面这样的问题:1.屏蔽checkbox的点击事件
android:clickable="false" android:focusable="false" android:focusableInTouchMode="false"
private static HashMap<Integer,Boolean> isSelected;
public static HashMap<Integer,Boolean> getIsSelected() { return isSelected; } public static void setIsSelected(HashMap<Integer,Boolean> isSelected) { MyDocShowAdapter.isSelected = isSelected; }
mHolder.mCheckBox.setChecked(getIsSelected().get(position));
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()); } });
1.屏蔽checkbox的点击事件
android:clickable="false" android:focusable="false" android:focusableInTouchMode="false"
private static HashMap<Integer,Boolean> isSelected;
public static HashMap<Integer,Boolean> getIsSelected() { return isSelected; } public static void setIsSelected(HashMap<Integer,Boolean> isSelected) { MyDocShowAdapter.isSelected = isSelected; }
mHolder.mCheckBox.setChecked(getIsSelected().get(position));
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()); } });
Android listview在使用checkbox的问题解决方案
原文地址:http://blog.csdn.net/elinavampire/article/details/42843751