How To Set Drawable Name To Imageview Programmatically

[Solved] How To Set Drawable Name To Imageview Programmatically | Scala - Code Explorer | yomemimo.com
Question : android imageview set image from drawable programmatically

Answered by : hannan

In XML : android:background="@drawable/imagename android:src="@drawable/imagename"
In Code :	imageview.setImageResource(R.drawable.imagename);

Source : | Last Update : Sat, 13 Nov 21

Question : how to set drawable name to imageview programmatically

Answered by : stockholm

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);

Source : https://stackoverflow.com/questions/11737607/how-to-set-the-image-from-drawable-dynamically-in-android | Last Update : Tue, 28 Apr 20

Answers related to how to set drawable name to imageview programmatically

Code Explorer Popular Question For Scala