xxxxxxxxxx
In XML :
android:background="@drawable/imagename
android:src="@drawable/imagename"
In Code :
imageview.setImageResource(R.drawable.imagename);
xxxxxxxxxx
img=(ImageView)findViewById(R.id.imageview1);
Drawable myDrawable = getResources().getDrawable(R.drawable.imageView1);
img.setImageDrawable(myDrawable);
xxxxxxxxxx
String uri = "@drawable/myresource"; // where myresource (without the extension) is the file
int imageResource = getResources().getIdentifier(uri, null, getPackageName());
imageview= (ImageView)findViewById(R.id.imageView);
Drawable res = getResources().getDrawable(imageResource);
imageView.setImageDrawable(res);
xxxxxxxxxx
var myImageList = intArrayOf(R.drawable.ic_food_image, R.drawable.ic_foodchicken,R.drawable.ic_foodchicken,R.drawable.ic_food_image)
holder.binding.ivFoodItem.setImageResource(myImageList[position % myImageList.size])