Issue
At the moment I set a marker image for google maps on android like this:
.icon(BitmapDescriptorFactory.fromResource(R.drawable.mon1))
Where mon1
is the name of the corresponding to a image called mon1.png
in drawable folder.
How can I do it like this:
String imagename="blablaimage";
.icon(BitmapDescriptorFactory.fromResource(R.drawable.imagename))
Solution
It is not possible to do what you suggested.
Instead, a possible workaround might be to use the following function:
public int getDrawableId(String name){
try {
Field fld = R.drawable.class.getField(name);
return fld.getInt(null);
} catch (Exception e) {
e.printStackTrace();
}
return -1;
}
and use like:
String imagename="blablaimage";
.icon(BitmapDescriptorFactory.fromResource(getDrawableId(imagename)));
Answered By - Lino
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.