复选框重复检查列表视图中 [英] Checkbox check repeats in listview
本文介绍了复选框重复检查列表视图中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下实现自定义的ListView使用的CursorAdapter填充:
I have the following implementation of a custom ListView populated using a CursorAdapter:
private class CurAdapter extends CursorAdapter{
public CurAdapter(Context context, Cursor c, int flags) {
super(context, c, flags);
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
final ViewHolder holder = (ViewHolder) view.getTag();
String name = (cursor.getString(cursor.getColumnIndexOrThrow("NotificationDateFor")));
String image = cursor.getString(cursor.getColumnIndexOrThrow("imageUri"));
holder.nametext.setText(name);
setImage(image, holder.iv);
holder.chk.setOnClickListener(onchk);
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
View view = LayoutInflater.from(context).inflate(R.layout.group_list, null);
ViewHolder holder = new ViewHolder(view);
view.setTag(holder);
return view;
}
private View.OnClickListener onchk = new View.OnClickListener() {
@Override
public void onClick(View v) {
}
};
public class ViewHolder {
TextView nametext;
RoundedImageView iv;
CheckBox chk;
public ViewHolder(View view){
iv = (RoundedImageView)view.findViewById(R.id.imageView2);
nametext = (TextView) view.findViewById(R.id.textView1);
chk = (CheckBox) view.findViewById(R.id.checkBox1);
}
}
}
我使用的是持有人的模式,以避免重复,但我得到检查盒随机检查时滚动我的名单,我该怎么会错过吗?
I am using a Holder pattern to avoid repetition, but I get check-boxes checked at random while scrolling my list, what do I miss here?
另外我想知道如何点击复选框的值存储在我的复选框的onClick。
Also I want to know how to store the values of clicked checkboxes in my onClick of the checkbox.
推荐答案
您创建一个像
List<Integer> positionList
和适配器getviewMethod
and adapter getviewMethod
checbox.setCheckedChanged method in
positionList.add(position);
和
for(Integer int:positionList){
if(int==position){
yourCheckBox.setChecked(true);
}
}
} }
这篇关于复选框重复检查列表视图中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文