I am getting this error and I really can’t understand why. The code:
b1.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
boolean b = true;
if(b == true){
tv1.setText("true");
b2.setEnabled(false);
b = false;
} else
if(b == false){
b2.setEnabled(true);
b = true;
tv1.setText("false");
As you can see I’m trying to make when a button is clicked it will check if variable “b” is true or false and then it should do the following code. But it doesn’t! It only does the actions for the “if b == true”. Can you help me?
Maybe because b is always true following this statement:
Also, b being a boolean, you can simply write:
This might work as you expect (not tested):