这个 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);
}
}
任何帮助表示赞赏。