How do I limit the user to put an hour marker in Android studio?

0

Very good I'm working on an app in Android studio where I have to show a map. Here the user must have the option of touching a button and be able to add a marker on the map while touching a button and be able to remove the marker. Apart from this the user should be allowed to add a marker per hour. For this problem I have come up with only one solution. Said solution is the following: Each time the user adds a bookmark, a delete button appears and the added button disappears. Analogously happens if I touch the delete button. The problem is that it does not succeed in making the aggregate button disappear, which allows the user to add more than one marker. This is my code:

 public Marker addMarker(Location location){
        if(mMap != null && location != null){
            LatLng gps = new LatLng(location.getLatitude(), location.getLongitude());
            marker = mMap.addMarker(new MarkerOptions().position(gps));
            marker.setDraggable(true);
            return marker;
        }
        return null;
    }

    public void drawMarker(View view){
        Location loc = returnLocation();
        marker = addMarker(loc);
        dialogPlayas.dismiss();
        removeMarker = findViewById(R.id.remove);
        removeMarker.setVisibility(View.VISIBLE);
        dialogPlayas = findViewById(R.id.addMarker);
        addMarker.setVisibility(View.GONE);
        Handler markerHandler = new Handler();
        markerHandler.postDelayed(timeRemoveMarker,3600000); //van a durar ua hora osea 3600000 milisegundos
    }

    private Runnable timeRemoveMarker = new Runnable() {
        @Override
        public void run() {
            addMarker.setVisibility(View.VISIBLE);
            marker.remove();
        }
    };



    public void removeMarkerButton(View view) {
        if (marker != null) {
            marker.remove();
            addMarker.setVisibility(View.VISIBLE);
            removeMarker.setVisibility(View.GONE);
        }
    }

As you can see, the delete button appears in my main activity (map) but the aggregate in an alert dialog that is called from the map. The problem is that every time I play in it, it does not disappear and that is eliminated. Any suggestions? I've been with this problem for days.

    
asked by Guillermo Noblega 29.10.2017 в 16:50
source

1 answer

1

Take the references of the method button:

public void drawMarker(View view){
        Button addMarker = (Button)view;
        addMarker.setVisibility(View.GONE);

        Location loc = returnLocation();
        marker = addMarker(loc);
        dialogPlayas.dismiss();
        removeMarker = findViewById(R.id.remove);
        removeMarker.setVisibility(View.VISIBLE);
        dialogPlayas = findViewById(R.id.addMarker);

        Handler markerHandler = new Handler();
        markerHandler.postDelayed(timeRemoveMarker,3600000); //van a durar ua hora osea 3600000 milisegundos
    }

Another reason that may be happening is that your handler is making your button visible again when it launches the thread and executes:

 addMarker.setVisibility(View.VISIBLE);
    
answered by 30.10.2017 в 22:40