-2

I have strange issue. My application have multiple activitys, on one activity is setting with two check boxes couple of spinners and save button.

When it first start, after installation I click button that bring up setting and in setting activity is this this on create:

    final CheckBox checkBox1st = (CheckBox) findViewById(R.id.checkBox1st);
    final CheckBox checkBox2nd = (CheckBox) findViewById(R.id.checkBox2nd);

    // set checkers from sharesetting

    String XX = GetPreference("lajna", "1");

    if (XX == "1") {
        checkBox1st.setChecked(true);
        checkBox2nd.setChecked(false);
        //updatneme spiner s menami podla lajn
        db.openToRead();
        updateSpiner("1"); //update appropriate spinner
        db.close();
    }  
    if (XX == "2") {
        checkBox1st.setChecked(false);
        checkBox2nd.setChecked(true);
        //updatneme spiner s menami podla lajny
        db.openToRead();
        updateSpiner("2"); //update appropriate spinner 
        db.close();
    }

so point of this is to read the shared setting and set checkbox as set ... but it doesnt do it at first, and the shared preference value is set.. even if it would not it still should go with value 1 no ? but it doesn't check any checker..

if I save the setting or use back button and than go to setting again it shows normal...

any idea why it is behave like this ?

Thanks, Vlad

VladoPortos
  • 563
  • 5
  • 21

1 Answers1

2

"1".equals(XX), string comparison should use equals not ==.

kosa
  • 65,990
  • 13
  • 130
  • 167
  • will try that and report back – VladoPortos Jan 30 '12 at 20:25
  • great it worked ! very strange I'm going to google whats the difference as in my mind its the exact same function. in any case thanks a lot I will use for string equals from now on. – VladoPortos Jan 30 '12 at 20:41
  • Check this discussion http://stackoverflow.com/questions/594604/string-equality-vs-equality-of-location – kosa Jan 30 '12 at 20:44