In my android application, there are number of images in drawable folder. In my layout there are two buttons: Back and Next buttons. On clicking next and back buttons 2 diff
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;
With kotlin you can disable a button with
button.isEnabled = false
or to disable clicking on it
button.isClickable = false
next.setClickable(false);
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
just insert two extra images in your drawable folder one for disabled right arrow and one for disabled left arrow.
now try this
case R.id.next:
Log.i("Tag","tag");
if(imageCounter < imageList.length)
{
imageCounter++;
imagePath = imageList[imageCounter];
if (imageCounter==(imageList.length)-1)
{
//disabling right button by changing image from following code
next.setImageDrawable(getResources().getDrawable(R.drawable.right_disabled));
}
}
break;
case R.id.back:
if(imageCounter > 0)
{
imageCounter--;
imagePath = imageList[imageCounter];
if (imageCounter==0)
{
back.setImageDrawable(getResources().getDrawable(R.drawable.left_disabled));
}
}
break;