【发布时间】:2012-05-05 06:44:53
【问题描述】:
这个 Android 视图回收的东西非常疯狂,我花了一整天的时间试图找到一个解决方法。
这是我的代码,它不起作用
public class CustomCursorAdapter extends SimpleCursorAdapter {
private Context currentContext;
private Cursor mCursor;
private boolean[] rows;
public CustomCursorAdapter(Context context, int layout, Cursor c,
String[] from, int[] to) {
super(context, layout, c, from, to);
// TODO Auto-generated constructor stub
currentContext = context;
mCursor = c;
populateRows();
}
private void populateRows() {
rows = new boolean[mCursor.getCount()];
int i = 0;
while (mCursor.moveToNext()) {
rows[i] = false;
i++;
}
}
@Override
public View getView(int position, View v, ViewGroup parent) {
// convertView.setBackgroundColor(R.drawable.darkred);
if (v != null) {
//getting checkbox
CheckBox cb = (CheckBox) v.findViewById(R.id.name);
if(rows[position]){
rows[position] = false;
}else{
rows[position] = true;
}
cb.setChecked(rows[position]);
}
return super.getView(position, v, parent);
}
}
感谢任何帮助。
【问题讨论】:
-
你能说得更具体一点吗?你想做什么?什么不工作?怎么不工作?您提供的信息越多,获得的帮助就越好。
-
我正在从 db 返回游标,并且复选框的此选中状态与任何 db 列无关,它仅用于向用户显示选择了哪些行。后来我将选定的值添加到数据库中的另一个表中,并且该部分正在工作我只是无法使复选框的这种选择正常工作
标签: android list checkbox android-cursoradapter