简体   繁体   English

回收站中的Imageview

[英]Imageview in a recyclerview

I have an imageview in row.xml and I set a picture for it in xml layout. 我在row.xml中有一个imageview,并在xml布局中为其设置了图片。 But when I use that in adapter (onbindviewholder method) Not show any image . 但是当我在适配器(onbindviewholder方法)中使用它时,不显示任何图像。 But when I set image resource in onbindviewholder that works and show the image !!! 但是,当我在onbindviewholder中设置可以正常工作并显示图像的图像资源时! What is wrong in the first method ??? 第一种方法有什么问题???

use 采用

holder.Image.setImageResource();

or you can use Glide or Picasso library to load images. 或者您可以使用Glide或Picasso库加载图像。

and also return the size of your list. 并返回列表的大小。

    @Override
    public int getItemCount() {
        return contacts.size();
    }
public class Adapter extends RecyclerView.Adapter<Adapter.vh> {
    private List<Contacts> contacts;

    public Adapter(List<Contacts> contacts) {
        this.contacts = contacts;
    }

    public class vh extends RecyclerView.ViewHolder {
        protected TextView first_name;
        protected TextView last_name;
        protected ImageView Image;

        public vh(View v) {
            super(v);
            first_name = (TextView) v.findViewById(R.id.first);
            last_name = (TextView) v.findViewById(R.id.last);
            Image = (ImageView) v.findViewById(R.id.imageView);
        }
    }

    @Override
    public Adapter.vh onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.row, parent, false);
        return new vh(v);
    }

    @Override
    public void onBindViewHolder(vh holder, int position) {
        Contacts example = contacts.get(position);
        holder.first_name.setText(example.name);
        holder.last_name.setText(example.last_name);
        if (position == 3) {
            holder.first_name.setTextColor(Color.BLUE);
        }
    }

    @Override
    public int getItemCount() {
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM