0

So although I am not new to programming (I have been developing for iOS for about 6 months not) I have just started to learn Android development and wanted to make the simplest app ever:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Button buckysButton = (Button)findViewById(R.id.buckysButton);

    buckysButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View vw) {
            TextView buckysText = (TextView)findViewById(R.id.buckysText);
            if (buckysText.getText().toString() == "Hello") buckysText.setText("World!");
            else if (buckysText.getText().toString() == "World!") buckysText.setText("Hello");
        }
    });
}

I get no errors. However, nothing happens when I press the button. Nothing changes, and yes, I am positive that my tables original text is set to 'Hello' because this is what I have my label set to in strings.xml. <string name="message_text">Hello</string>

WeSt
  • 2,628
  • 5
  • 22
  • 37
user3127854
  • 107
  • 1
  • 2
  • 8
  • possible duplicate of [How do I compare strings in Java?](http://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java) – matiash Dec 26 '14 at 20:56

1 Answers1

0

NEVER use == on a String! ALWAYS use .equals() on a String!

See this question for further explanations: Java String.equals versus ==

Community
  • 1
  • 1
TronicZomB
  • 8,667
  • 7
  • 35
  • 50