カーソルアダプタを使用するチェックボックス付きのlistViewがあります。何らかの理由で、ヘッダー(pageOrder == 3)をスクロールすると、あちこちに移動します。それは上にとどまりません。位置13、2、または3に移動します。何かアイデアはありますか?
public class ExamCursorAdapter extends CursorAdapter {
private LayoutInflater inflater;
private int pageIndex;
private int pageTitleIndex;
private int pageOrderIndex;
private Context context;
private String assessmentId;
static class ViewHolder{
protected TextView textViewTitle;
protected TextView textViewHeader;
protected TextView textViewCheckBox;
protected CheckBox checkbox;
protected int pageOrder;
protected int pageId;
}
public ExamCursorAdapter(Context context, Cursor cursor, String assessmentId) {
super(context, cursor, 0);
this.context = context;
this.assessmentId = assessmentId;
pageIndex = cursor.getColumnIndex(PagesTable.COLUMN_ID);
pageTitleIndex = cursor.getColumnIndex(PagesTable.COLUMN_TITLE);
pageOrderIndex = cursor.getColumnIndex(PagesTable.COLUMN_ORDER);
inflater = LayoutInflater.from(context);
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
ViewHolder holder = (ViewHolder) view.getTag();
holder.textViewTitle.setText(cursor.getString(pageTitleIndex));
holder.pageOrder = cursor.getInt(pageOrderIndex);
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
ViewHolder holder = new ViewHolder();
View view = null;
holder.pageId = cursor.getInt(pageIndex);
holder.pageOrder = cursor.getInt(pageOrderIndex);
if(holder.pageOrder == 3) {
view = inflater.inflate(R.layout.list_adapter_header_exam, null);
holder.textViewTitle = (TextView) view.findViewById(R.id.adapter_header_textview_exam_column1);
holder.textViewCheckBox = (TextView) view.findViewById(R.id.adapter_header_textview_exam_column2);
holder.textViewCheckBox.setText("Complete");
view.setFocusable(true);
} else {
view = inflater.inflate(R.layout.exam_row, null);
holder.textViewTitle = (TextView) view.findViewById(R.id.exam_cursor_adapter_textview);
holder.checkbox = (CheckBox) view.findViewById(R.id.exam_cursor_adapter_check_box);
holder.checkbox.setClickable(false);
String[] projection = { ExamCompleteTable.COLUMN_EXAM_COMPLETE };
StringBuilder sb = new StringBuilder();
sb.append(BPContentProvider.EXAM_COMPLETE_URI).append("/assessment/").append(assessmentId);
sb.append("/page/").append(holder.pageId);
Uri examCompleteUri = Uri.parse(sb.toString());
Cursor examCompleteCursor = context.getContentResolver().query(examCompleteUri, projection, null, null, null);
if (examCompleteCursor.moveToFirst()) {
int examComplete = examCompleteCursor.getInt(examCompleteCursor.getColumnIndexOrThrow(ExamCompleteTable.COLUMN_EXAM_COMPLETE));
if(examComplete == 1) {
holder.checkbox.setChecked(true);
}
}
examCompleteCursor.close();
}
view.setTag(holder);
return view;
}
}