automatic onClick

-1

Greetings to all, by chance someone knows how you can make a button to be clicked only after a few seconds.

Something like in Waze that one chooses the route and a Button appears (Go now) which after a few seconds is pressed only activating the desired route.

    
asked by Guillo F 27.09.2017 в 00:45
source

2 answers

3

Try the method postDelayed of the class Handler , specifying the time:

final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
  @Override
  public void run() {
    //ejecutas metodo click del boton aqui
  }
}, 1000); // 1000 = 1 segundo
    
answered by 27.09.2017 / 01:03
source
1

To run the button use the performClick () method; , to be executed in a certain time, use a Handler, define the number of milliseconds that you want to run a process or in this case the action related to the click of a button:

int TIEMPO = 10000; //como ejemplo 10 segundos (10,000 milisegundos)

new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {

                //Ejecuta clic en boton, metodo o proceso.
                myButton.performClick();

            }
        }, TIEMPO);
    
answered by 27.09.2017 в 02:02