Home > Net >  how to create a timer minutes by pressing the button?
how to create a timer minutes by pressing the button?

Time:05-13

how to create a timer for 2 minutes by pressing the button? I want to create a button that after pressing this button will unclicable for 2 minutes

CodePudding user response:

Try this --

use Handler(import android.os.Handler;)

  btn.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        btn.setEnabled(false);

     new Handler().postDelayed(new Runnable() {

        @Override
        public void run() {
            // This method will be executed once the timer is over
                btn.setEnabled(true);
                Log.d(TAG,"resend1");

        }
    },120000);// set time as per your requirement 
    }
});
  • Related