这个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);
}
}
感谢任何帮助。
答案 0 :(得分:0)
这里有很多不妥之处: