Why onCreateView on my RecyclerView Adapter is not called?

Razvan Mişu Costescu :

So I have a RecyclerView inside another RecyclerView. And in my onBind() method in recyclerView1 i am trying to set the data for recyclerView2 , the fact is that recyclerView1 has a FirebaseRecyclerAdapter and recyclerView2 has a custom RecyclerAdapter and the onCreate() method in recyclerView2's adapter is never called , so the data set is good but it doesn't create my recyclerView2 in the interface this recycler is empty.

I put a breakpoint on the OrderViewHolder onCreateViewHolder and it just skips this .

Here is the code from the recyclerView2's adapter onCreate and onBind methods :

 adapterReceivedCommands = new FirebaseRecyclerAdapter<Comanda, ReceivedCommandsViewHolder>(optionsReceivedCommands) {

        @NonNull
        @Override
        public ReceivedCommandsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
            View itemView = LayoutInflater.from(parent.getContext())
                    .inflate(R.layout.item_command,parent,false);
            layoutManagerOrder = new GridLayoutManager(parent.getContext(),3);
            orderRecycler = (RecyclerView) itemView.findViewById(R.id.order_recycler);
            orderRecycler.setLayoutManager(layoutManagerOrder);
            fragmentItem = (LinearLayout)itemView.findViewById(R.id.item_layout);
            return new ReceivedCommandsViewHolder(itemView);


        }

        @Override
        protected void onBindViewHolder(@NonNull final ReceivedCommandsViewHolder receivedCommandsViewHolder, int i, @NonNull final Comanda comanda) {


            receivedCommandsViewHolder.tableNmb.setText(comanda.getmasa());
            orderModelArrayList = comanda.getcomanda();
            mAdaptor = new RecyclerViewAdapter(this, orderModelArrayList);
            receivedCommandsViewHolder.recyclerView.setAdapter(mAdaptor);
        }


    };
    adapterReceivedCommands.startListening();
    receivedCommandsRecycler.setAdapter(adapterReceivedCommands);

    return view;
}

And here is the code from the custom recyclerView2's adapter :

 public class RecyclerViewAdapter extends RecyclerView.Adapter<OrderViewHolder>{

private ArrayList<OrderModel> orderModels = new ArrayList<OrderModel>();
private FirebaseRecyclerAdapter<Comanda, ReceivedCommandsViewHolder> context;

public RecyclerViewAdapter(FirebaseRecyclerAdapter<Comanda, ReceivedCommandsViewHolder> context, ArrayList<OrderModel> orderModels) {
    this.orderModels = orderModels;
   this.context = context;
}

@NonNull
@Override
public OrderViewHolder onCreateViewHolder(@NonNull ViewGroup parent, final int viewType) {
    View view = LayoutInflater.from(parent.getContext())
            .inflate(R.layout.item_order,parent,false);
    OrderViewHolder holder = new OrderViewHolder(view);


    return holder;
}

@Override
public void onBindViewHolder(@NonNull OrderViewHolder holder, int position) {
    OrderModel curentModel = orderModels.get(position);
            holder.cantitateTxt.setText(curentModel.getCantitate().toString());
            holder.comandaTxt.setText(curentModel.getDenumireProdus());
}

@Override
public int getItemCount() {
    return 0;
}
Ryan Mentley :

Your item count is zero:

@Override
public int getItemCount() {
    return 0;
}

So RecyclerView doesn't see any items to inflate. You should fix it to return the size of your list:

@Override
public int getItemCount() {
    return orderModels.size();
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=238449&siteId=1