Skip to content Skip to sidebar Skip to footer

Imageview In A Recyclerview

I have an imageview in row.xml and I set a picture for it in xml layout. But when I use that in adapter (onbindviewholder method) Not show any image . But when I set image resource

Solution 1:

use

holder.Image.setImageResource();

or you can use Glide or Picasso library to load images.

and also return the size of your list.

    @Override
    publicintgetItemCount() {
        return contacts.size();
    }

Solution 2:

publicclassAdapterextendsRecyclerView.Adapter<Adapter.vh> {
    private List<Contacts> contacts;

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

    publicclassvhextendsRecyclerView.ViewHolder {
        protected TextView first_name;
        protected TextView last_name;
        protected ImageView Image;

        publicvh(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);
        }
    }

    @Overridepublic Adapter.vh onCreateViewHolder(ViewGroup parent, int viewType) {
        Viewv= LayoutInflater.from(parent.getContext()).inflate(R.layout.row, parent, false);
        returnnewvh(v);
    }

    @OverridepublicvoidonBindViewHolder(vh holder, int position) {
        Contactsexample= 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);
        }
    }

    @OverridepublicintgetItemCount() {
    }
}

Post a Comment for "Imageview In A Recyclerview"