Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 762319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:56:38+00:00 2026-05-14T15:56:38+00:00

Calling setFocus(null) on the ItemizedOverlay does not ‘unfocus’ current marker. According to the documentation:

  • 0

Calling setFocus(null) on the ItemizedOverlay does not ‘unfocus’ current marker. According to the documentation:

… If the Item is not found, this is a no-op. You can also pass null to remove focus.

Here’s my code:

MapItemizedOverlay

public class MapItemizedOverlay extends ItemizedOverlay<OverlayItem> {
    private ArrayList<OverlayItem> items = new ArrayList<OverlayItem>();

    public MapItemizedOverlay(Drawable defaultMarker) {
        super(defaultMarker);
    }

    public void addOverlay(OverlayItem overlay) {
        items.add(overlay);
        populate();
    }

    @Override
    protected OverlayItem createItem(int i) {
        return items.get(i);
    }

    @Override
    public int size() {
        return items.size();
    }

}

Creating map overlay and one marker:

StateListDrawable youIcon = (StateListDrawable)getResources().getDrawable(R.drawable.marker_icon);
int width = youIcon.getIntrinsicWidth();
int height = youIcon.getIntrinsicHeight();
youIcon.setBounds(-13, 0-height, -13+width, 0);
GeoPoint location = new GeoPoint(40800816,-74122009);

MapItemizedOverlay overlay = new MapItemizedOverlay(youIcon);
OverlayItem item = new OverlayItem(location, "title", "snippet");
overlay.addOverlay(item);
mapView.getOverlays().add(overlay);

The R.drawable.marker_icon is defined as follows:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_focused="true" android:drawable="@drawable/marker_selected" />
    <item android:state_selected="true" android:drawable="@drawable/marker_selected" />
    <item android:drawable="@drawable/marker_normal" />
</selector>

Now, to test the setFocus() behavior I put the button on the activity window, with the following onClick listener:

Button focusBtn = (Button)findViewById(R.id.focusbtn);
focusBtn.setOnClickListener(new OnClickListener() {             
    @Override
    public void onClick(View v) {
        for(Overlay ov : mapView.getOverlays())
        {
            if(ov.getClass().getSimpleName().equals("MapItemizedOverlay") == true)
            {
                MapItemizedOverlay miv = (MapItemizedOverlay)ov;
                if(miv.getFocus() == null)
                    miv.setFocus(miv.getItem(0));
                else
                    miv.setFocus(null);
                break;
            }
        }
        mapView.invalidate();
    }
});

The expected behavior is: clicking on the button toggles marker selection.

It works only once – clicking it for the first time selects the marker, clicking it again does not de-select the marker. The most weird thing about it is that after calling setFocus(null), getFocus() also returns null – like the overlay has no focused item (I debugged it). But even after calling mapView.invalidate() the marker is still drawn in ‘selected'(focused) state.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T15:56:39+00:00Added an answer on May 14, 2026 at 3:56 pm

    As Rpond said in a comment to my question, it looks like an open bug in the API.

    In the meantime I solved it myself. Below is the workaround code. You need to extend the OverlayItem class and check what overlay.getFocus() is returning.

    public class MapOverlayItem extends OverlayItem {
    
        MapItemizedOverlay overlay = null;
    
        public MapOverlayItem(GeoPoint point, MapItemizedOverlay ov)
        {
            super(point, null, null);
            this.overlay = ov;
        }
    
        public MapOverlayItem(GeoPoint point, String title, String snippet) {
            super(point, title, snippet);
        }
    
        @Override
        public Drawable getMarker(int stateBitset) {
            Drawable icon = overlay.getDefaultMarker();
    
            if(stateBitset == 0)
                return icon;
    
            OverlayItem focusedItem = overlay.getFocus();
    
            if(focusedItem == null) {
                OverlayItem.setState(icon, 0);
                return icon;
            }
    
            if(focusedItem.equals(this) == true)
                OverlayItem.setState(icon, stateBitset);
            else
                OverlayItem.setState(icon, 0);
    
            return icon;        
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.