Skip to main content

How to change the marker for the overlay on tap for android?


i have made an application in which i need to change the drawable of an overlayitem when a user clicks on it. i am using the following code to achieve this effect:




protected boolean onTap(int index) {
OverlayItem item = mOverlays.get(index);
if(item.getTitle().equals("true")){
if(item.getMarker(OverlayItem.ITEM_STATE_FOCUSED_MASK).equals(greenMarker)){
item.setMarker(orangeMarker);
view1ComplainPoleList.add(item.getSnippet());
Log.i("adding",item.getSnippet());
map.invalidate();
}
else{
item.setMarker(greenMarker);
view1ComplainPoleList.remove(item.getSnippet());
Log.i("removing",item.getSnippet());
map.invalidate();
}
}
return true;
}



But this does not seem to be working. whenever i click on an overlayitem it disappears from view. what is going wrong?



UPDATE:



could you also tell me how to load new views when the map is scrolled...?



thank you in advance.


Source: Tips4allCCNA FINAL EXAM

Comments

  1. This is very simple to do:

    protected boolean onTap(int index) {
    OverlayItem item = mOverlays.get(index);
    //Get the new Drawable
    Drawable marker = mContext.getResources().getDrawable(R.drawable.icon);
    //Set its bounds
    marker.setBounds(0,0,marker.getIntrinsicWidth(),marker.getIntrinsicHeight());
    //Set the new marker
    item.setMarker(marker);
    //Return true! Do not invalidate
    return true;
    }

    ReplyDelete
  2. I have no idea what view1ComplainPoleList is and whether it is impacting matters. I handled this by subclassing OverlayItem and overriding getMarker() to return the proper image. Here is the sample project in which I use this technique.

    ReplyDelete

Post a Comment

Popular posts from this blog

Slow Android emulator

I have a 2.67 GHz Celeron processor, 1.21 GB of RAM on a x86 Windows XP Professional machine. My understanding is that the Android emulator should start fairly quickly on such a machine, but for me it does not. I have followed all instructions in setting up the IDE, SDKs, JDKs and such and have had some success in staring the emulator quickly but is very particulary. How can I, if possible, fix this problem?