Never compare strings with == in Java. Use equals().

On Sun, Sep 4, 2011 at 6:07 PM, erik wagner <[email protected]> wrote:
> Hi,
> I'm having a bit of a problem with the return values from
> preferences.getString.  The value that I'm getting returned doesn't
> seem to be correct.
> This snippet will not evaluate correctly (i'm omitting the
> toast.length_long ending since it formats squirrelly).  This always
> goes to the else (i.e. 'nothing') condition.  There are only two
> possible values ("Two" and "Four").
>
> String strTemp=prefs.getString("listPlayers", "");
> if (strTemp=="Two") {
>      Toast.makeText(WarGamePlay.this, "two?",
> } else if (strTemp=="Four") {
>      Toast.makeText(WarGamePlay.this, "four?",
> } else {
>      Toast.makeText(WarGamePlay.this, "nothing?",
> }
>
> If i exchange the prefs.getString with just...
>
> String strTemp="Two";
>
> then that correctly goes to the first condition in the if/else tree.
>
> What am I missing?  I have checked the values coming back from the
> prefs.getString and there are no leading/trailing spaces or anything
> else visually wrong that I can see with the value.
> Any help on this would be appreciated.  Thanks in advance.
> Erik Wagner
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>



-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

_The Busy Coder's Guide to Android Development_ Version 3.6 Available!

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to