E
E
Elfry2018-05-22 21:11:53
android studio
Elfry, 2018-05-22 21:11:53

How to temporarily block a button in Android Studio?

After pressing, it is necessary to block the button for a few seconds, and then make it active again. Preferably with sample code.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
ivanessence, 2018-05-23
@Elfry

Thread.sleep is not an option.
Try using Handler with a delayed call, handler.postDelayed

S
Semyon Novikov, 2018-05-23
@semennovikov123

Button button = (Button) findViewById(R.id.Button);
button.setOnClickListener( new OnClickListener() {

      @Override
       public void onClick(View v) {
               button.setEnabled(false);
               Thread.sleep(5000);  // пауза на 5 секунд
               button.setEnabled(true); 
               }
    });

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question