Ofek Ron
Ofek Ron

Reputation: 8580

Choosing Drawable to show on a imageview programmatically

I have say N images that i want to include in my android project resources, say image0 to imageN-1, how do I set an image view to show one of those drawables say imagei when i is known only at runtime?

something like that:

imageView.setImageDrawable(getResources().getDrawable("R.drawable.image"+i));

obviously that wouldnt work but you know what i mean...

Thanks!

Upvotes: 0

Views: 578

Answers (1)

Alexander
Alexander

Reputation: 48232

You can use Resources.getIdentifier() as in this blog explained

Upvotes: 2

Related Questions