I am able to display multiple overlayItems on Googlemap, now I want to change icon of any specific overlayItem (to show it is currently selected event). I want to do it through navigation buttons (next, previous) as on Google maps.
I am using StateListDrawable to display icons for OverlayItems.
Icon file is
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:an开发者_如何学运维droid="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:drawable="@drawable/selected_icon"/>
<item android:drawable="@drawable/unselected_icon"/>
</selector>
code for getMarker method of OverlayItem is as follows.
@Override
public android.graphics.drawable.Drawable getMarker(int stateBitset){
Drawable icon;
icon = this.mapActivity.getResources().getDrawable(R.drawable.film_icon);
icon.setBounds(0, 0, icon.getIntrinsicWidth(), icon.getIntrinsicHeight());
return icon;
}
Now my question is how do I change the state of any overlayItem/Icon on map when user click on one of navigation keys?
Any help is much appreciated.
Did you try to use the method setState(int id)?
Basically you can either use the predefined states defined as XML attributes for the StateListDrawable and set the state according to their IDs (i.e. android.R.attr.state_active) or you can add your own states using addState(int[] stateSet, Drawable drawable).
I did not try it myself so can't conclude it is working.
精彩评论