Issue
Avoid this if possible. Step back and rethink if you really need to do it this way as it is an expensive operation and probably there are better ways of doing it.
Solution
You can use the method to convert string into int identifier:
public static int getStringIdentifier(Context context, String name) {
return context.getResources().getIdentifier(name, "drawable", context.getPackageName());
}
Pass in an activity as context parameter (or any other Context instance). Then you can use the identifier as usual with getString() method.
Note that conversion from string to identifier uses reflection and thus can be not that fast, so use carefully.
Refer to : This SO post
Example use : number1.setImageResource(getStringIdentifier(this,String.valueOf(n+rnd)));
Answered By - Randyka Yudhistira
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.