0

I have this code wherein it comes from an intent. The variable is status and such could be final or notfinal I was able to alert if I have passed the variable in my current intent. And it shows such alert. Moreover, I want that my checkbox in my xml will be checked if the status value is final and if not there will be no check at all. And such does not work. Any help will do. Thanks! Here's my code snippet:

status = i.getString("a_status");
//alert(status);
if (status =="notfinal")
final_checkbox.setChecked(true);
user3319349
  • 15
  • 1
  • 4

4 Answers4

0

try this way: instead of == operator used string.equals() method

   if (status.equals("final")){

     final_checkbox.setChecked(true);

     }else{

     //do something
     }
M D
  • 47,665
  • 9
  • 93
  • 114
0

You can't compare tow String using ==. You have compare as string1.equals(string2)...It will be better to use equalsIgnoreCase() than equals().

if (status.equalsIgnoreCase("notfinal")){
        final_checkbox.setChecked(true);
}
Hamid Shatu
  • 9,664
  • 4
  • 30
  • 41
0

compare the String using equals()

change this if (status =="notfinal") to if (status .equals("notfinal"))

Nambi
  • 11,944
  • 3
  • 37
  • 49
0

Firstly, if your status may take just two values, I'd suggest using a Boolean variable instead a String.

Said that, you're getting the value by calling .getString(). You should call getStringExtra() instead as this returns the extras you might have provided at call time. And if you finally use a String, use .equals() or equalsIgnoreCase() instead. For instance:

if (status.equalsIgnoreCase("notfinal")) { ... }
nKn
  • 13,691
  • 9
  • 45
  • 62