Disable button after a click for 2 seconds and resume back

Viewed 8224

When I click a resend button first time, the button will disable for 2 seconds.After 2 seconds the button will enable? I am using this code

    btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            btn.setEnabled(false);
            btn.postDelayed(new Runnable() {
                public void run() {
                    btn.setEnabled(true);
                    Log.d(TAG,"resend1");
                }
            },1000);
        }
    });

But this code is not working properly.

3 Answers
Related