Reputation: 37
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 in onbindviewholder that works and show the image !!! What is wrong in the first method ???
Upvotes: 0
Views: 9141
Reputation: 37
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() {
}
}
Upvotes: 0
Reputation: 10101
use
holder.Image.setImageResource();
or you can use Glide or Picasso library to load images.
and also return the size of your list.
@Override
public int getItemCount() {
return contacts.size();
}
Upvotes: 2