Thanks very much!  I have to say though my (ignorant) questions are
not over.  I am ultra newbie on Java and am not sure how to write a
(working) Equals method.
This is the body of the Equals I wrote
public boolean equals(String strTemp) {
      SharedPreferences
prefs=PreferenceManager.getDefaultSharedPreferences(this);
      if (strTemp instanceof String) {
            String strP1 = prefs.getString("listPlayers", "");
            if (this.equals(strP1)) return true;
      }
      return false;
}

in the code i'm trying to do something along the lines of
if ((equals("Two") {
    // blah blah
}

I know this is a basic-really-should-know-how-to question but I'm kind
of flailing on the whole thing.  Thanks.


On Sep 4, 5:08 pm, Mark Murphy <[email protected]> wrote:
> 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/commonsguyhttp://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