Android ImageView setImageResource in code

后端 未结 5 474
太阳男子
太阳男子 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:40

    You can use this code:

    // Create an array that matches any country to its id (as String):
    String[][] countriesId = new String[NUMBER_OF_COUNTRIES_SUPPORTED][];
    
    // Initialize the array, where the first column will be the country's name (in uppercase) and the second column will be its id (as String):
    countriesId[0] = new String[] {"US", String.valueOf(R.drawable.us)};
    countriesId[1] = new String[] {"FR", String.valueOf(R.drawable.fr)};
    // and so on...
    
    // And after you get the variable "countryCode":
    int i;
    for(i = 0; i

提交回复
热议问题