Android - Method setOnMarkerClickListener execute the second click

1

I want to know if you can perform the setOnMarkerClickListener method, but perform the scheduled task on the second click.

 googleMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
                @Override
                public boolean onMarkerClick(Marker marker) {



                }
            });

EJ: I have a google maps marker, which shows information, I want to press once to show the information, and if you pressed twice I sent to an activity that I already have created.

    
asked by Fernando Brito 26.06.2018 в 05:17
source

1 answer

-1

For this you can use the same method onMarkerClick() but using a handler you can validate if it takes more than a second and a half between clicks, it is a click if both clicks occur in less than a double click:

Declare a variable at class level:

boolean doubleClick = false;

This would be the way to detect a click or double:

        map.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
            @Override
            public boolean onMarkerClick(Marker marker) {

                if (doubleClick) {

                    //DOBLE CLICK 
                    // ABRE ACTIVITY

                    Intent intent = new Intent(MainActivity.this, OtraActivity.class);
                    startActivity(intent);
                } else {

                    //UN CLICK
                    // Muestra información

                    doubleClick = true;
                    new Handler().postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            doubleClick = false;
                        }
                    }, 1500); //1.5 segundos
                }
                return false;
            }
        });
    
answered by 26.06.2018 / 22:22
source