-1

I'm trying a simple check. If a string name locale has "es" as value.

public String locale = 
    Locale.getDefault().getLanguage().toLowerCase().toString();

// ...

Log.v(tag, "Idioma del sistema: «" + locale +"»");
if (locale != "es") {
    showDialog(R.string.warningTitleDialog, 
        "We are sorry that this tool is only available in Spanish " +
        "language. See Author menu item for more information. [" + 
        locale + "]");
    locale = "en";
}

adb logcat shows "es" as content of string "locale" but code inside the condition is being executed.

hakre
  • 193,403
  • 52
  • 435
  • 836
DRoBeR
  • 1
  • 1

2 Answers2

2

It seem that problem is not of android or of logic this is in JAVA. Try this and tell us what is happening

if(!locale.equals("en"))
{
   //Your Code
}
jignesh Vadadoriya
  • 3,244
  • 3
  • 18
  • 29
2

Never use != or == in association with strings. Try the method equals like this:

if(locale.equals("es"))

This will return true if the strings locale and "es" contain the same character sequence. Because the equals( ) method compares the characters inside a String object. The == operator compares two object references to see whether they refer to the same instance.

See What is the difference between == vs equals() in Java? for more information.

Community
  • 1
  • 1
Steve Benett
  • 12,843
  • 7
  • 59
  • 79