-1

I have around 18 views and a button that has onclicklisteners. My goal is to disable the listeners on the 18 views once the button is clicked to avoid them from getting flipped over again once they are pressed.

My problem: after i have initialized the onclicklisteners those 18 views still has their listeners and stil doing the method being called once they are clicked. I have tried setting click listeners to null and setting clickable to false and they are still clickable. Any way to disable theses views from being pressed? Method to disable:

 private void makeUnclickable() {
    for (int x = 9; x < 9; x++) {
        front[x].setOnClickListener(null);
        back[x].setOnClickListener(null);
        front[x].setClickable(false);
        back[x].setClickable(false);
    }
}
leenolasco
  • 75
  • 10

1 Answers1

0

Take a boolean variable and store the state of the button you want to enable or disable.Then:

 public void onClick(View v)
{

      if(isEnabled)
        {
        //write your click listeners here
        }
else
      {
      return true;
        }
}
Rushi Ayyappa
  • 2,708
  • 2
  • 16
  • 32