STATUS NOT CHANGING ON BUTTON PRESS IN ANDROID

Monaj Singh

Total Post:41

Points:287
Posted by  Monaj Singh
 1043  View(s)
Ratings:
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;

  1. Anurag Sharma

    Post:40

    Points:280
    Re: Status not changing on button press in android

    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

      Modified On Apr-06-2018 06:56:10 AM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!