recyclerview.onbindviewholder始終處于位置 0public class NoteAdapter extends RecyclerView.Adapter<NoteAdapter.ViewHolder> { public static final int UNCOMPLETED = 0; public static final int COMPLETED = 1; public static final int HIGHTLIGHT = 2; public static final int HIGHTLIGHT_COMPETED = 3; Cursor cursor; Context context; public NoteAdapter(Context context, Cursor cursor) { this.context = context; this.cursor = cursor; } public Cursor getCursor() { return this.cursor; } public void setCursor(Cursor cursor) { this.cursor = cursor; } public Context getContext() { return context; } public void setContext(Context context) { this.context = context; } @Override public int getItemViewType(int position) { if (cursor.moveToPosition(position)) { cursor.move(position); String content = cursor.getString(cursor.getColumnIndex(DatabaseHandler.KEY_CONTENT)); int completed = cursor.getInt(cursor.getColumnIndex(DatabaseHandler.KEY_COMPLETED)); int hightlight = cursor.getInt(cursor.getColumnIndex(DatabaseHandler.KEY_HIGHTLIGHT)); if (completed == 1) { if (hightlight == 1) { return HIGHTLIGHT_COMPETED; } return COMPLETED; } if (hightlight == 1 && completed == 0) { return HIGHTLIGHT; } return UNCOMPLETED; } return -1; }該程序不包含任何錯誤。當我運行程序時,它總是只顯示0位置的元素,其余位置不顯示。函數getItemCount正常工作,返回 20 個元素。英語不是我的母語,很抱歉有任何語法錯誤。感謝大家。
1 回答

慕斯王
TA貢獻1864條經驗 獲得超2個贊
確保android:layout_height
各種 ViewHolders 的布局(xml)文件中的父布局已設置wrap_content
為而不是match_parent
。
添加回答
舉報
0/150
提交
取消