Android ImageView setImageResource in code

后端 未结 5 488
太阳男子
太阳男子 2020-12-13 05:01

I have an imageView that I want to display a little icon of the country that you are currently in. I can get the country code, but problem is I can\'t dynamically change the

5条回答
  •  醉话见心
    2020-12-13 05:37

    One easy way to map that country name that you have to an int to be used in the setImageResource method is:

    int id = getResources().getIdentifier(lowerCountryCode, "drawable", getPackageName());
    setImageResource(id);
    

    But you should really try to use different folders resources for the countries that you want to support.

提交回复
热议问题