此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);
}
}
任何帮助表示赞赏。
你能更具体,以创建新实例,例如。你想做什么?什么不起作用?它怎么不工作?您提供的信息越多,您获得的帮助就越多。 – Gophermofur 2012-04-24 15:38:52
即时通讯从数据库返回光标和复选框的此选中状态不与任何数据库列相关,它仅用于显示给用户哪些行被选中。后来我将选定的值添加到数据库中的另一个表,该部分工作,我只是不能使这个选择框复选框正常工作 – 2012-04-24 17:07:24