我有一个RecycleView,其中包含固定数量的CardView(在我的情况下为14),其中一些卡可能是两种类型layouts for cardView中的一种。而且......我的问题是如何在代码中实现它?
我有一个RecycleItem类:
public class RecyclerItem {
private String title;
private String description;
public RecyclerItem(String _title, String _description, boolean _weekEnd) {
this.title = _title;
this.description = _description;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public void getWeekEnd(boolean _weekEnd){
this.weekEnd = _weekEnd;
}
public boolean getWeekEnd(){
return this.weekEnd;
}
}
适配器的和类:
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> {
private List<RecyclerItem> listItems;
private Context mContext;
public MyAdapter(List<RecyclerItem> listItems, Context mContext) {
this.listItems = listItems;
this.mContext = mContext;
}
public class ViewHolder extends RecyclerView.ViewHolder{
public TextView title, description;
public ViewHolder(View itemView) {
super(itemView);
title = (TextView) itemView.findViewById(R.id.titleOfTheCard);
description = (TextView) itemView.findViewById(R.id.descriptionOfTheCard);
}
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
return new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.card, parent, false));
}
@Override
public void onBindViewHolder(final ViewHolder holder, @SuppressLint("RecyclerView") final int position) {
final RecyclerItem itemList = listItems.get(position);
holder.title.setText(itemList.getTitle());
holder.description.setText(itemList.getDescription());
}
@Override
public int getItemCount() {
return listItems.size();
}
}
我只是在填写recycleView项目列表以及如何正确填写时,不知道如何更改c卡的“类型”,那么你能帮我解决吗?
另一个问题。你知道有关开发应用程序的好文献吗? 对于Android?