Java RecyclerView未填充项,而Adapter和ArrayList已包含数据
Java RecyclerView未填充项,而Adapter和ArrayList已包含数据,java,android,arraylist,android-recyclerview,Java,Android,Arraylist,Android Recyclerview,recycerViewOrderNewItem和offlineOrderProductListProductList是两个recyclerviews,它们是在onCreate()方法中初始化的 recycerViewOrderNewItem = findViewById(R.id.recycerViewOrderNewItem); recycerViewOrderNewItem.setLayoutManager(new LinearLayoutManager(ge
recycerViewOrderNewItem
和offlineOrderProductListProductList
是两个recyclerviews
,它们是在onCreate()方法中初始化的
recycerViewOrderNewItem = findViewById(R.id.recycerViewOrderNewItem);
recycerViewOrderNewItem.setLayoutManager(new LinearLayoutManager(getApplicationContext()));
offlineOrderProductListProductList = findViewById(R.id.offlineOrderProductListProductList);
offlineOrderProductListProductList.setLayoutManager(new LinearLayoutManager(getApplicationContext()));
下面是我作为List
请帮我解决这个问题…我认为您应该初始化适配器并清晰地查看回收器
allItemsOfOrder可以像这样是全局的
然后,您应该将订单添加到列表中
allItemsOfOrder可以像这样是全局的
然后你应该通知你的适配器如下
mAdapter.notifyDataSetChanged();
您可以将其用作参考 请提供适配器代码。1。您是否检查了recyclerview的xml,以确保没有使用match parent作为recyclerview项的高度?2.调试RecycleView适配器类中的代码,以确保RecycleView实际看到arraycheck,如果RecycleView单独工作,则对每个类进行注释。如果这样做很可能是因为XMLheight=match\u parent
的问题。我总是对recyclerView使用wrap\u内容。两个recyclerView是同一个页面吗?
offlineOrderProductListProductList.setAdapter(new NewOrderEntryAdapter(OrderEntryActivity.this, (ArrayList<NewOrderEntryModel>) allItemsOfOrder));
recycerViewOrderNewItem.setAdapter(new NewOrderEntryAdapter(OrderEntryActivity.this, (ArrayList<NewOrderEntryModel>) allItemsOfOrder));
public class NewOrderEntryAdapter extends RecyclerView.Adapter<NewOrderEntryAdapter.NewOrderEntryAdapterViewHolder>{
private Context context;
private ArrayList<NewOrderEntryModel> newOrderEntryModels;
public NewOrderEntryAdapter(Context context, ArrayList<NewOrderEntryModel> newOrderEntryModels) {
this.context = context;
this.newOrderEntryModels = newOrderEntryModels;
}
@NonNull
@Override
public NewOrderEntryAdapterViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context).inflate(R.layout.list_item_order_entry_detail,parent,false);
return new NewOrderEntryAdapterViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull NewOrderEntryAdapterViewHolder holder, final int position) {
NewOrderEntryModel orderEntryModel = newOrderEntryModels.get(position);
//Data
final String name = orderEntryModel.getProductName();
final String totalPrice = String.valueOf(orderEntryModel.getPBSalesTotal());
final String code = String.valueOf(orderEntryModel.getPCode());
final String quantity = String.valueOf(orderEntryModel.getPBInQty());
final String price = String.valueOf(orderEntryModel.getPBSalesPrice());
final String productID = String.valueOf(orderEntryModel.getPBProductID());
// Binding
holder.tvProductNameOrderEntry.setText(name);
holder.tvProductTotalPriceOrderEntry.setText(totalPrice);
holder.tvProductCodeOrderEntry.setText(code);
holder.tvProductQuantityOrderEntry.setText(quantity);
holder.tvProductPriceOrderEntry.setText(price);
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Toast.makeText(context, "Reference id: "+orderEntryModel.getPBRefID()+" Table ID: "+orderEntryModel.getID(), Toast.LENGTH_SHORT).show();
if(orderEntryModel.getPBRefID()==null){
//Toast.makeText(context, "Reference id: "+orderEntryModel.getPBRefID()+" Table ID: "+orderEntryModel.getID(), Toast.LENGTH_SHORT).show();
openDetailActivity(String.valueOf(position),"","",name,totalPrice,code,quantity,price,productID);
}else {
Toast.makeText(context, "Reference id: "+orderEntryModel.getPBRefID()+" Table ID: "+orderEntryModel.getID(), Toast.LENGTH_SHORT).show();
openDetailActivity(String.valueOf(position),Integer.toString(orderEntryModel.getID()),orderEntryModel.getPBRefID(),name,totalPrice,code,quantity,price,productID);
}
//Toast.makeText(context, context.toString(), Toast.LENGTH_SHORT).show();
}
});
}
@Override
public int getItemCount() {
return newOrderEntryModels.size();
}
public class NewOrderEntryAdapterViewHolder extends RecyclerView.ViewHolder{
public TextView tvProductNameOrderEntry
,tvProductTotalPriceOrderEntry
,tvProductCodeOrderEntry
,tvProductQuantityOrderEntry
,tvProductPriceOrderEntry;
public NewOrderEntryAdapterViewHolder(View itemView) {
super(itemView);
tvProductNameOrderEntry = itemView.findViewById(R.id.tvProductNameOrderEntry);
tvProductTotalPriceOrderEntry = itemView.findViewById(R.id.tvProductTotalPriceOrderEntry);
tvProductCodeOrderEntry = itemView.findViewById(R.id.tvProductCodeOrderEntry);
tvProductQuantityOrderEntry = itemView.findViewById(R.id.tvProductQuantityOrderEntry);
tvProductPriceOrderEntry = itemView.findViewById(R.id.tvProductPriceOrderEntry);
}
}
public void openDetailActivity(String position,
String id,
String pbRef,
String productName,
String totalPrice,
String productCode,
String quantity,
String productPrice,
String productID){
Intent intent = new Intent(context, NewItemDetailActivity.class);
intent.putExtra("position",position);
intent.putExtra("id",id);
intent.putExtra("pbRef",pbRef);
intent.putExtra("productName",productName);
intent.putExtra("totalPrice",totalPrice);
intent.putExtra("productCode",productCode);
intent.putExtra("quantity",quantity);
intent.putExtra("productPrice",productPrice);
intent.putExtra("productID",productID);
context.startActivity(intent);
}
}
List<NewOrderEntryModel> allItemsOfOrder = new ArrayList<>();
recyclerView = (RecyclerView) findViewById(R.id.recycerViewOrderNewItem);
mAdapter = new NewOrderEntryAdapter(this,allItemsOfOrder);
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());
recyclerView.setLayoutManager(mLayoutManager);
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setAdapter(mAdapter);
allItemsOfOrder.add(/*Something*/);
mAdapter.notifyDataSetChanged();