所以我有一个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
您的商品数为零:
@Override
public int getItemCount() {
return 0;
}```
因此RecyclerView看不到任何要膨胀的物品。您应该对其进行修复以返回列表的大小:
@Override public int getItemCount() { return orderModels.size(); }```
回答来源:Stack Overflow
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。