Android ListView和复选框-复选框没有像教程中那样被勾选
在过去的几个小时里,我一直在阅读教程和论坛帖子,试图实现一个简单的复选框列表视图 我理解(我相信)我需要如何维护列表中复选框的状态(在我的例子中是映射) 我确信这是一件非常简单的事情,但是在我的bindView方法中,我的复选框没有设置为true或false。这是密码Android ListView和复选框-复选框没有像教程中那样被勾选,android,cursor,simplecursoradapter,Android,Cursor,Simplecursoradapter,在过去的几个小时里,我一直在阅读教程和论坛帖子,试图实现一个简单的复选框列表视图 我理解(我相信)我需要如何维护列表中复选框的状态(在我的例子中是映射) 我确信这是一件非常简单的事情,但是在我的bindView方法中,我的复选框没有设置为true或false。这是密码 public void bindView(View view, Context context, Cursor cursor) { final int rowId = cursor.getInt(cursor.ge
public void bindView(View view, Context context, Cursor cursor) {
final int rowId = cursor.getInt(cursor.getColumnIndexOrThrow("_id"));
familyText = (TextView)view.findViewById(R.id.contacts_row_family_name);
markedBox = (CheckBox)view.findViewById(R.id.contacts_row_check);
familyText.setText(cursor.getString(cursor.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME)));
view.setOnClickListener(new OnClickListener(){
public void onClick(View arg0) {
Log.d("OnClick","Row clicked");
boolean currentlyChecked;
if(checkedState.size() >= rowId){
currentlyChecked = checkedState.get(rowId);
checkedState.put(rowId, !currentlyChecked);
}else{
currentlyChecked = false;
checkedState.put(rowId, !currentlyChecked);
}
markedBox.setChecked(checkedState.get(rowId));
}
});
setProgressBarIndeterminateVisibility(false);
}
这是checkedState的声明。这是我活动的班级成员
private Map<Integer, Boolean> checkedState = new HashMap<Integer,Boolean>();
私有映射checkedState=newhashmap();
据我所知,我应该在该行设置一个侦听器(这可以正常工作,因为我的日志消息打印正确),但复选框没有更改。更新:
我错了,我的复选框没有被选中。正在检查的只是错误的一个。我将结束这个问题