-1

For example, the name of the image is got from the following code

Bundle bundle = getIntent().getExtras();
String name = bundle.getString("Name");

And what i would like to do is like

int picId = R.drawable.name;

where name should be replaced by the actual name. How can I do that? Or is there an alternative way so that I could show the picture in ImageView? I tried to put the image in the database which worked, but it makes the database way too large.

  • 2
    Why not passing the integer reference to the drawable using the Bundle, instead of a String ? It would certainly make things a lot easier... – 2Dee Nov 06 '13 at 13:48
  • Please check this as well http://stackoverflow.com/questions/19724094/string-value-to-a-varaiable/19724382#19724382 – jagmohan Nov 06 '13 at 13:49
  • thank you,will you please mark my answer as correct one – Dinesh Raj Nov 08 '13 at 03:07

1 Answers1

0

Try this

Bundle bundle = getIntent().getExtras();
 String name = bundle.getString("Name");

 int resId = getResources().getIdentifier(name, "drawable", getPackageName());
Dinesh Raj
  • 664
  • 12
  • 30