在活动中设置reclerview时的字节分配问题

时间:2017-03-26 21:56:27

标签: android android-recyclerview android-arrayadapter

在为一个图像和两个textview设置recylerview时出现错误 我不知道错误的含义。我已经阅读了一些文档,但我找不到合适的文档。我在持有者类

中提到了下面的错误行

小帮助会很棒。谢谢!

适配器类:

ismember

持有人类:

public class SlipAdapter extends RecyclerView.Adapter<SlipDataHolder> {

    private List<StringList> slipList;

    public SlipAdapter(){
        slipList=new ArrayList<>();
        slipList.add(new StringList("Slip-1","100$/day",R.drawable.table));
        slipList.add(new StringList("Slip-2","200$/day",R.drawable.tablenew));
        slipList.add(new StringList("Slip-3","300$/day",R.drawable.table));
        slipList.add(new StringList("Slip-4","400$/day",R.drawable.tablenew));
        slipList.add(new StringList("Slip-5","1500$/day",R.drawable.table));
        slipList.add(new StringList("Slip-6","600$/day",R.drawable.tablenew));
        slipList.add(new StringList("Slip-7","700$/day",R.drawable.table));
        slipList.add(new StringList("Slip-8","800$/day",R.drawable.tablenew));
        slipList.add(new StringList("Slip-9","900$/day",R.drawable.table));
        slipList.add(new StringList("Slip-10","1000$/day",R.drawable.tablenew));

    }

    @Override
    public SlipDataHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        Context context =parent.getContext();
        LayoutInflater inflater=(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view=inflater.inflate(R.layout.layout_slip,parent,false);
        return new SlipDataHolder(view);

    }

    @Override
    public void onBindViewHolder(SlipDataHolder holder, int position) {

        StringList s=slipList.get(position);
        holder.bindSlip(s);}

    @Override
    public int getItemCount() {
        return slipList.size();}}

名称等级:

public class SlipDataHolder extends RecyclerView.ViewHolder {

    private TextView nameOfSlip;
    private TextView priceOfSlip;
    private ImageView slipImage;

    public SlipDataHolder(View itemView) {
        super(itemView);

        nameOfSlip=(TextView) itemView.findViewById(R.id.name_of_slip);
        priceOfSlip=(TextView) itemView.findViewById(R.id.rate_of_slip);
        slipImage=(ImageView) itemView.findViewById(R.id.image_slip);
    }

    public void bindSlip(StringList stringList) {
        nameOfSlip.setText(stringList.stringSlipName);
        priceOfSlip.setText(stringList.stringPrice);
        slipImage.setImageResource(stringList.stringImage); //error line
    }
}

logcat的:

public class StringList {
    public String stringSlipName;
    public String stringPrice;
    public int stringImage;

    public StringList(String stringSlipName, String stringPrice, int stringImage) {
        this.stringImage = stringImage;
        this.stringPrice = stringPrice;
        this.stringSlipName = stringSlipName;
    }

}

1 个答案:

答案 0 :(得分:1)

通过减少所有图像的大小我删除了我的错误!