RecyclerView.Adapter onCreateViewHolder and methods onBindViewHolder do not get

I am trying to implement TwoWayView in my project, following the sample project presented in this link. I implemented everything, and my code works without errors, but the actual list is not inflated. After debugging, I learned that the adapter is configured correctly, and the method getItemCountalso returns a positive score, but the other two overridden methods onCreateViewHolder, and onBindViewHolderare not called. I do not know why it does not work. See Partial Code below, any help is appreciated. Thanks.

class MyAdapter.java

public class MyAdapter extends RecyclerView.Adapter < MyViewHolder > {

    private MySimpleCursorAdapter mCursor;
    //some other private fields here

    public MyAdapter(Context context, Cursor c, int resourceId, ViewType viewType, String containerId) {
        mCursor = new MySimpleCursorAdapter(a1,a2,a3,a4,a5,a6); //Passed necessary arguments
        ....
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        Log.w("onCreateViewHolder", "--------->executed"); //Line not executed
        final View view = mCursor.newView(mContext, mCursor.getCursor(), parent);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        Log.w("onBindViewHolder", "--------->executed"); //Line not executed
        mCursor.bindView(holder.itemView, mContext, mCursor.getCursor());
    }

    @Override
    public int getItemCount() {
        Log.w("count", Integer.toString(mCursor.getCount())); //This is executed
        return mCursor.getCount();
    }

    private class MySimpleCursorAdapter extends SimpleCursorAdapter {

        public MySimpleCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to, int flags) {
            super(context, layout, c, from, to, flags);
        }

        @Override
        public View newView(Context context, Cursor cursor, ViewGroup parent) {
            View view = mLayoutInflater.inflate(mLayoutToInflate, null);
            ....
            return view;
        }

        @Override
        public void bindView(final View view, Context context, Cursor cursor) {
            //Implemented this method for inflating all subviews inside each item of the list
        }
    }
 }

:. , , RecyclerView ScrollView, getItemCount .

+4
2

, setLayoutManager(LayoutManager) recycler. getItemCount().

yourRecyclerview.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));

+9

-, :

public class MyAdapter extends RecyclerView.Adapter < MyViewHolder > {

private MySimpleCursorAdapter mCursor;
private Context context;  // <-- add this line
//some other private fields here

public MyAdapter(Context context, Cursor c, int resourceId, ViewType viewType, String containerId) {
    mCursor = new MySimpleCursorAdapter(a1,a2,a3,a4,a5,a6); 
    this.context = context;  // <-- add this line
    //Passed necessary arguments
    ....
}

onCreateViewHolder , ViewHolder:

    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    Log.w("onCreateViewHolder", "--------->executed"); //Line not executed
    final View view = mCursor.newView(context, mCursor.getCursor(), parent);
    return new MyViewHolder(view);
}

CursorAdapter :

        public View newView(Context context, Cursor cursor, ViewGroup parent) {
        View view = LayoutInflater.from(context).inflate(mLayoutToInflate, parent, false);
        return view;
    }

, JSON , .

0

Source: https://habr.com/ru/post/1606457/


All Articles