BB Developer
BB Developer

Reputation: 374

Set Google Maps API V2 markers draggable attribute to false after creating it?

So I create a marker and make it draggable. It works good. I am trying to make this only true when in edit markers mode. My problem is when I am not in edit mode I cant turn it off. I have tried in setOnMarkerClickListener by doing marker.setDraggable(false) but that only works if the user clicks the marker first then tries to drag it, I have tried doing it in the onMarkerDragStart section but only works after the marker is dragged once but then since the marker is not draggable it never goes back to that section even in edit mode to turn it back on. I need a way to turn all markers draggability false when not in edit mode and true in edit mode. Any help would be so very much appreciated!

Upvotes: 0

Views: 431

Answers (1)

xsorifc28
xsorifc28

Reputation: 5131

I'm not sure what you mean by "edit mode". If I understood correctly, you have a markers that you want to make non-draggable. Make a new ArrayList and as you create a marker, add it to the list

For example:

// Make the list
ArrayList<Marker> mMarkerList;

// Make a new marker
Marker x = mMap.addMarker(...);

// Add market to the list
mMarkerList.add(x);

Now, to make them all non-draggable, make a loop which iterates through the list of markers.

Edit

set the markers dragable in a loop

public void myEditMode(boolean start){
    for (Marker marker:mMarkerList) {
        marker.setDragable(start);
    }
}

Upvotes: 1

Related Questions