开发者社区> 问答> 正文

为什么未调用RecyclerView Adapter上的onCreateView?

所以我有一个RecyclerView内心RecyclerView。而在我的onBind()方法,recyclerView1我想设置的数据recyclerView2,事实是,recyclerView1有一个FirebaseRecyclerAdapter和recyclerView2具有自定义RecyclerAdapter和onCreate()在方法recyclerView2的adapter永远不会被调用,因此该数据集是好的,但它并没有创造我recyclerView2的界面这个回收站是空的。

我在上设置了一个断点OrderViewHolder onCreateViewHolder,它跳过了这个。

这是recyclerView2的adapter onCreate和onBind方法中的代码:

 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;
}```
这里是从自定义代码recyclerView2的adapter:

public class RecyclerViewAdapter extends RecyclerView.Adapter {

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

public RecyclerViewAdapter(FirebaseRecyclerAdapter<Comanda, ReceivedCommandsViewHolder> context, ArrayList 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; }```

问题来源:Stack Overflow

展开
收起
montos 2020-03-27 21:54:17 690 0
1 条回答
写回答
取消 提交回答
  • 您的商品数为零:

    @Override
    public int getItemCount() {
        return 0;
    }```
    因此RecyclerView看不到任何要膨胀的物品。您应该对其进行修复以返回列表的大小:
    

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

    回答来源:Stack Overflow

    2020-03-27 21:54:52
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载