我有一个包含3个项目的列表。我希望列表中的所有3个项目都可以通过RecyclerView的3个不同的CardView进行渲染。 但是,它只显示1张卡。
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder>{
private List<DishBO> dishItemsList;
public class ViewHolder extends RecyclerView.ViewHolder{
CardView cv;
public TextView dishName,dishPrice,dishQuantity;
public ViewHolder(View view){
super(view);
cv=(CardView)view.findViewById(R.id.dishListCardView);
dishName=(TextView)view.findViewById(R.id.dishNameEditText);
dishPrice=(TextView)view.findViewById(R.id.dishPriceEditText);
dishQuantity=(TextView)view.findViewById(R.id.dishQuantityEditText);
}
}
public MyAdapter(List<DishBO> dishItemsList){
this.dishItemsList=dishItemsList;
}
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType){
View itemView= LayoutInflater.from(parent.getContext()).inflate(R.layout.dish_list_row,parent,false);
return new ViewHolder(itemView);
}
@Override
public void onBindViewHolder(final ViewHolder holder,final int position){
DishBO ob=dishItemsList.get(position);
TextView textViewDishName=holder.dishName;
TextView textViewDishPrice=holder.dishPrice;
TextView textViewDishQuantity=holder.dishQuantity;
textViewDishName.setText(String.valueOf(ob.getDishName()));
textViewDishPrice.setText(String.valueOf(ob.getCostPrice()));
textViewDishQuantity.setText(String.valueOf(ob.getQuantity()));
}
@Override
public int getItemCount(){
return dishItemsList.size();
}
}
dishItemsList是3个项目的列表。