Issue
I would like to replace the default ImageView with a random drawable file. I'm trying to use a string that will call a resource_name in java with a variable string that changes based on the user's input.
JAVA code
String random1 = userinput_1;
String random2 = userinput_2;
String replaceImageView = (random1+"_"+random2);
orignalImageView.setImageResource(R.drawable.replaceImageView);
Solution
You need to get the identifier using the name, then use it as you would normally
String random1 = userinput_1;
String random2 = userinput_2;
String replaceImageView = (random1+"_"+random2);
int drawableResourceId = this.getResources().getIdentifier(replaceImageView, "drawable", this.getPackageName());
orignalImageView.setImageResource(drawableResourceId);
Answered By - Alirio Mendes
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.