为了账号安全,请及时绑定邮箱和手机立即绑定

recyclerview.onBindviewholder 始终处于位置 0

recyclerview.onBindviewholder 始终处于位置 0

MYYA 2024-01-17 21:02:46
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



查看完整回答
反对 回复 2024-01-17
  • 1 回答
  • 0 关注
  • 46 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信