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

  • SEARCH
  • Home
  • 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 8692065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:14:44+00:00 2026-06-13T00:14:44+00:00

I am trying to allow a User to remove a point (or more specifically,

  • 0

I am trying to allow a User to remove a point (or more specifically, an OverlayItem) from a map. I followed the developer tutorial to get started and implemented the CustomMapView in this tutorial to capture a long press on the map.

So now I have a program which allows a User to place points on the map. My next goal is to let the User remove points. Here is my code for when a User clicks an existing point on the map.

public class OurItemizedOverlay extends ItemizedOverlay {

//Create new list of points
private ArrayList<OverlayItem> mapOverlays = new ArrayList<OverlayItem>();
private Context mapContext;
@Override
protected boolean onTap(final int index) {
    Button edit, remove;

    //Get index of item tapped
    OverlayItem item = mapOverlays.get(index);

    //Create Dialog to show point info, allow for edit or removal.
    LinearLayout layout = new LinearLayout(mapContext);
    layout.setOrientation(LinearLayout.VERTICAL);

    LayoutInflater inflater = LayoutInflater.from(mapContext);
    AlertDialog.Builder builder = new AlertDialog.Builder(mapContext);
    builder.setTitle(item.getTitle());
    builder.setMessage(item.getSnippet());

    View view = inflater.inflate(R.layout.view_or_edit_location_dialog, null);
    builder.setView(view); 
    builder.show();

    //BUTTONS

    edit = (Button)view.findViewById(R.id.edit);
    remove = (Button)view.findViewById(R.id.delete);

    //Edit Button Listener
    edit.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

        }
    });

    //Remove Button Listener
    remove.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            removeOverlay(index); <--------

            Log.d("View location info", "user clicked delete.");
            return;
        }
    });

    return true;
}

Here is my code for removeOverlay.

protected void removeOverlay(int index) {

    mapOverlays.remove(index);
    com.example.mapproject.MainActivity.mapView.invalidate();
}

After I click on an existing point a dialog is presented offering to remove the point. When I have selected to remove the point, the point still remains on the screen. If I place a new point, the ‘deleted’ one is removed. However, if I click the ‘deleted’ point or another existing point, the program crashes with this error.

error

If you have a clue of what to do, I’d appreciate to hear from you !!

Edit

Following a tip from Vishwa Patel, I remove a point from the map straight away using postInvalidate(). However, I still get indexoutofbounds exceptions when I click where the icon was..

  • 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-06-13T00:14:46+00:00Added an answer on June 13, 2026 at 12:14 am

    I believe I found the solution here. It seems to work so far, the answer was to put the following line into my removeOverlay method,

    setLastFocusedIndex(-1);
    

    The code to remove an OverylayItem from my custom Overlay is,

        protected void removeOverlay(OverlayItem overlayItem) {
    
        mapOverlays.remove(overlayItem);
        MainActivity.mapOverlays.remove(this);
        setLastFocusedIndex(-1);
        populate();
    
    }
    

    Any thoughts/suggestions are welcome!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I'm trying to add some ability to my project to allow user-defined properties
I trying to pomp showPermissionDialog for allow the user to post something in a
I am trying to set up a page that will allow the user to
I'm trying to modifty the Flex Tree control to allow a user to select
i'm trying to add some navigation arrows which allow the user to go to
I am trying to create a ListView with CheckBox's...Th ListView should allow the user
I am trying to expand the devise registration form to allow a new user
I'm trying to allow user to rename file name, after taking picture, but I
am trying to allow a user to delete a certain image with is in
I'm trying to find a way to strip tags from a user-inputted string except

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.