Skip to content
Advertisement

how to create a timer minutes by pressing the button? [closed]

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

Advertisement

Answer

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 
    }
});
Advertisement