0

the icon name is : icon1.png

.icon(BitmapDescriptorFactory.fromResource(R.drawable.icon1)));

I want to use the String icon_name
the String icon_name will be updated from server, but all the icons are in drawable. I just change the name, and the code should search in folder drawable.

That means, it should like that :

.icon(BitmapDescriptorFactory.fromResource(xxxxx icon_name)));

I have tried like that :

.icon(BitmapDescriptorFactory.fromResource(Integer.parseInt("R.drawable."+icon_name))));

android-studio accepts the format but it does not understand it as path.

how can I implement this to make to icon-name variable and not fixed?

I just want to change the Icon from Server from time to time.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Biblio
  • 43
  • 1
  • 6
  • So you just want to change the name of the image(icon1, icon2, etc..) not the path? – HB. Jul 07 '17 at 17:33
  • yes, only the name, not the path. I found at least a methode as solution for this case here : [link](https://stackoverflow.com/questions/3042961/how-do-i-get-the-resource-id-of-an-image-if-i-know-its-name) it works – Biblio Jul 07 '17 at 17:44
  • `getResources().getIdentifier(icon_name, "drawable", getPackageName());` – Biblio Jul 07 '17 at 18:23

0 Answers0