How to disable button click?

more preferred solution is,

onclick(){
  btn.setEnabled(false);
  btn.setClickable(false);
  //yourwork
  myWork();
}

myWork(){
 //your tasks.
 btn.setEnabled(true);
 btn.setClickable(true);
}

As a link can be ignored easily, I had to repeat this again and again


KOTLIN:

next.isClickable = false

JAVA:

next.setClickable(false);


case R.id.next:
        Log.i("Tag","tag");
        if(imageCounter < imageList.length)
        {
            imageCounter++;
            imagePath = imageList[imageCounter];
            if (imageCounter==(imageList.length)-1)
            {
                ImageButton next=(ImageButton)findViewBYId(R.id.next);
                next.setEnabled(false);
            }
        }
        break;
    case R.id.back:
        if(imageCounter > 0)
        {
            imageCounter--;
            imagePath = imageList[imageCounter];
            if (imageCounter==0)
            {
                ImageButton back=(ImageButton)findViewBYId(r.id.back);
                back.setEnabled(false);
            }
        }
        break;

Tags:

Android

Button