Issue
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.
Solution
Yes you can get the int id from String
Try This
int background = getResources().getIdentifier("background", "drawable", "com.example.package");
image.setImageResource(background);
Answered By - Vishal Chhodwani
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.