0
我一直在阅读过去几个小时的教程和论坛帖子,试图获得一个简单的复选框listview实现。我知道(我相信)我需要如何保持列表中的复选框的状态(o在我的情况下是地图)。ListView和复选框 - 复选框没有在教程中打勾
这是这样一个简单的事情,我敢肯定,但我的复选框没有被设置为true或false在我的bindView方法。这里是代码
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>();
据我所知,我应该有一个监听器(这是因为我的日志消息打印正确),但复选框不会改变。