I can not figure out how to write an image in the adapter RecyclerView in the method onBindViewHolder (images are stored in the drawable folder).
2 answers
Alternatively, you can access the array with the loaded images in the adapter:
private int[] images = {R.drawable.android_image_1, R.drawable.android_image_2, R.drawable.android_image_3, }; public void onBindViewHolder(ViewHolder viewHolder, int i) { viewHolder.itemImage.setImageResource(images[i]); } |
@Override public void onBindViewHolder(RecyclerView.ViewHolder baseHolder, final int position) { //set image in ImageView holder.ivIcon.setBackground(ContextCompat.getDrawable(context, R.drawable.yourDrawable)); } |