Assume you have several drawables in your Android resource folder and what to iterate over them. You use a certain naming schema and would like to use this to determine the resources ID’s.
The following snippets shows how to get a resource ID based on the resource name:
// Name of resource // Type // Package of the app int identifier = getResources().getIdentifier("pic1", "drawable","android.demo"); ImageView image = (ImageView) findViewById(R.id.imageView1); image.setImageResource(identifier);
I hope this helps.