我尝试使用CardView,在CardView中我放置了UI小部件2 TextViews和2个ImageViews。我的RecyclerView用于显示Cardviews列表
这是我的Java类模型:
public class Masar {
public String masarName;
public String masarDesc;
public int imgl;
public Masar(String masarName, String masarDesc) {
this.masarName = masarName;
this.masarDesc = masarDesc;
}
public Masar(String masarName, String masarDesc, int imgl) {
this.masarName = masarName;
this.masarDesc = masarDesc;
this.imgl = imgl;
}
public String getMasarName() {
return masarName;
}
public String getMasarDesc() {
return masarDesc;
}
public int getImgl() {
return imgl;
}
}
这是我的Adapter类:
public class MasarAdapter extends RecyclerView.Adapter<MasarAdapter.MyViewHolder> {
private Context mContext;
private List<Masar> masrList;
public MasarAdapter(Context mContext, List<Masar> masrList) {
this.mContext = mContext;
this.masrList = masrList;
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.masar_items, parent, false);
return new MyViewHolder(itemView);
}
@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
Masar masar=masrList.get(position);
holder.masarName.setText(masar.getMasarName());
holder.masarDesc.setText(masar.getMasarDesc());
}
@Override
public int getItemCount() {
return 0;
}
public class MyViewHolder extends RecyclerView.ViewHolder {
public TextView masarName, masarDesc;
public ImageView masarImg;
public MyViewHolder(View itemView) {
super(itemView);
masarName = (TextView) itemView.findViewById(R.id.masarName);
masarDesc = (TextView) itemView.findViewById(R.id.masarDesc);
masarImg = (ImageView) itemView.findViewById(R.id.imageView4);
}
}
}
我已经多次尝试找出为什么我得到空白的结果..你能帮忙解决我的问题吗?
答案 0 :(得分:0)
你在getItemCount()方法中返回0。
@Override
public int getItemCount() {
return 0;
}
应该是:
@Override
public int getItemCount() {
return masrList.size();
}