views:

415

answers:

1

Hi,

I am working on android application and I am able to displayed multiple icons on map using ItemizedOverlay and I have also implemented onTap(int index) method of ItemizedOverlay to display icon specific information in a required window.

Now, I want to change icon of selected overlay when user click on some other coponent. I am calling setFocus(OverlayItem) method of ItemizedOverlay to display different icon of specific overlay. it works fine when user tap on any specific overlay but does not change icon when I call setFocus(OverlayItem) method.

Any pointers? what is best way of programtically changing icon of selected overlay in mapView?

I have overriden getMarker method of my custom OverlayItem class to display different markers for different state of overlayItem. and I want to use setFocus(OverlayItem) method to change the state of OverlayItem and also change the marker when selected.

@Override
public Drawable getMarker(int stateBitset){
 if(stateBitset==0){
  icon = Util.getCategoryMapIcon(0);   
  icon.setBounds(0-icon.getIntrinsicWidth()/2, 0-icon.getIntrinsicHeight(), icon.getIntrinsicWidth()/2, 0);
  return icon;
 }else {
  icon = Util.getCategoryMapIcon(OverlayItem.ITEM_STATE_SELECTED_MASK);
  icon.setBounds(0-icon.getIntrinsicWidth()/2, 0-icon.getIntrinsicHeight(), icon.getIntrinsicWidth()/2, 0);
  return icon;   
 }
}

here Util.getCategoryMapIcon(0) is Utility method to return appropriate icon, this method takes some parameters, which I have removed to make this example look simple.

and below is code to change the state

Button leftNavigation = (Button) findViewById(R.id.left_navigation_button);
leftNavigation.setOnClickListener(new OnClickListener() {
 @Override
 public void onClick(View v) {
  OverlayItem item = searchResultsOverlay.get(index+1);
  setFocus(item);
 }
});

Any help will be much appreciated. Thanks, Aamir

A: 

In your getMarker code, try returning a StateListDrawable (which corresponds to <selector> in drawable XML) that contains a default drawable (no states) and a drawable with the android.R.attr.state_focused state.

See a related question here: http://stackoverflow.com/questions/2038040/android-listview-selector-color

Roman Nurik
Any luck with this answer? Feel free to follow up.
Roman Nurik
Hi Roman,I like the idea of using StateListDrawable, but now problem is how can I change the state of any OverlayItem on map. setFocus() is not the right method I think so.I want to change icon for one of the already displaying icon on the map. Just to show that is the selected icon. I want to do it on onTap(int) event of ItemizedOverlay and also onClick of next,previous buttons. see below map showing some icons and next, previous buttons.http://img502.imageshack.us/img502/5301/mapy.png
Aamir Yaseen