0

For example I have an image background1.jpg and I this is the code to get the ID

int background = R.drawable.background1;

I then uploaded int background to the database. I closed the app and open it again then I retrieved the ID from the database that was saved earlier and set it in an ImageView

int background = json.getInt("background");
image.setImageResource(background);

Is it possible to do this? Does the R.drawable.background1 changes from time to time? Because I was wondering why the background didn't change the second time I run my app.

Jhii
  • 117
  • 3
  • 14

1 Answers1

1

Yes you can get the int id from String

Try This

int background = getResources().getIdentifier("background", "drawable", "com.example.package");

image.setImageResource(background);
Vishal Chhodwani
  • 2,567
  • 5
  • 27
  • 40