Prevent double button click on android

0

I have a delivery application where clicking the button fires a request, it turns out that's going on a bug that even with a preventive code to enter, sometimes happens in milliseconds is fired two or more applications at the same time in the event by clicking the shooting, I believe this is happening due to more than one user click on the button (although it would have to be very fast even since shortly after it appears a dialog).

I was trying to make this not happen by putting the following code right after the button is clicked:

      //prevent two click the same time
        if (SystemClock.elapsedRealtime() - mLastClickTime < 30000) {
            Toast.makeText(getBaseContext(),"Aguarde 30 segundos para solicitar uma nova corrida",Toast.LENGTH_LONG).show();
            return;
        }

        mLastClickTime = SystemClock.elapsedRealtime();
    
asked by anonymous 07.10.2017 / 15:36

2 answers

0

You will have to set the method to disable the click event of the button, so you can control when the user can click the button, in which case he can click again after the request for the service is made, the code below can help you understand:

    onClick(View v){
        ChamarPedido();
    }


    private void ChamarPedido(){
        myButton.setClickable(false);
        //termine de fazer suas requisições e reeative o botão
        ClienteChamouPedido()
        myButton.setClickable(true);


    }
    
09.10.2017 / 21:26
-1

What I would do would be as follows, when the client clicks on order ("finish order") I would create an intent by sending it to the screen or a request status fragment.

    
09.10.2017 / 21:14