[Solved] Changing value of a variable on OnClick Android


Try This

void test()
{

  if(number<1) { number = 1; }

  Log.e("number value : ",String.valueOf(number));

  btn1.setOnClickListener(new View.OnClickListener() {
     @Override
     public void onClick(View arg0)  {
       if(number == 1)
       {
         number=2;
         Log.e("Button 1 number value : ",String.valueOf(number));
       }
     }
  });

  btn2.setOnClickListener(new View.OnClickListener() {
     @Override
     public void onClick(View arg0)  {
       if(number == 2)
       {
         number=1;
         Log.e("Button 2 number value : ",String.valueOf(number));
       }
     }
  });

}

1

solved Changing value of a variable on OnClick Android