Home > DeveloperSection > Forums > Status not changing on button press in android
Monaj Singh
Monaj Singh

Total Post:41

Points:287
Posted on    November-18-2014 10:28 PM

 Android Java  OnClicklistener 
Ratings:


 1 Reply(s)
 585  View(s)
Rate this:

Whenever I presses the button, it should change text, and also change boolean value, yet this is not working. Any help? Thnks

Before onCreate:

public boolean status = false;

Button Click:

case R.id.saveButton:  

if (status != true) {

    currentStatus.setText("Current status: In need of help!");

    status = true;

}

if (status != false) {

    currentStatus.setText("Current status: Fine.");

    status = false;

}

break;



Anurag Sharma
Anurag Sharma

Total Post:40

Points:280
Posted on    November-19-2014 12:07 AM

if(status){

       currentStatus.setText("Current status: Fine.");

       status = false;

}else {                            

       currentStatus.setText("Current status: In need of help!");

       status = true

}

or using ternary operator :

currentStatus.setText(status ? "Current status: Fine." : "Current status: In need of help!");

status = !status;//toggle boolean value


Don't want to miss updates? Please click the below button!

Follow MindStick