Android ListView嵌套checkbox点击事件

<CheckBox
        android:id="@+id/checkbox_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:clickable="false"
        android:focusable="false" />

adapter添加:

public static Map<Integer, Boolean> isSelected;
private boolean defulat = false;

// 初始化
private void init() {
	// 这儿定义isSelected这个map是记录每个listitem的状态,初始状态全部为false。
	isSelected = new HashMap<Integer, Boolean>();
	for (int i = 0; i < mvList.size(); i++) {
		isSelected.put(i, defulat);
	}
}

holderView.checkbox = (CheckBox) convertView.findViewById(R.id.checkbox_view);
holderView.checkbox.setChecked(isSelected.get(position));

public static Map<Integer, Boolean> getIsSelected() {
		return isSelected;
	}

public static void setIsSelected(Map<Integer, Boolean> isSelected) {
		MainAdapter.isSelected = isSelected;
	}


activity的List点击事件:

private HolderView hv;

listContent.setOnItemClickListener(new OnItemClickListener() {
	@Override
	public void onItemClick(AdapterView<?> arg0, View view, int position, long id) {
		hv = (HolderView) view.getTag();
		if (hv.checkbox.isChecked())
			hv.checkbox.setChecked(false);
		else
			hv.checkbox.setChecked(true);
		boolean check = hv.checkbox.isChecked();
		MainAdapter.isSelected.put(position, check);
		}
	});



阅读更多
上一篇Android HorizontalScrollView实现横向Gallery
下一篇Android Studio 图片选择器
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭