Possible Duplicate:
How do I compare strings in Java?
I dont understand why the the first (same for other ones) if
in sendMessage never gets true. The reciever String is exactly what it should be to be true?!
When i run this and press send to Alice I get 3 Toast:
- Send to Alice (=value of reciever)
- [a blank toast] (=value of phoneNumber)
You have to choose a message (=nevermind this!)
public void onSend(View src){ Button b = (Button)src; sendMessage(b.getText().toString()); } public void sendMessage(String reciever){ String phoneNumber = ""; Toast.makeText(this, reciever, Toast.LENGTH_LONG).show(); if (reciever == "Send to Alice"){ phoneNumber = "01230340645"; Toast.makeText(this, "hej", Toast.LENGTH_LONG).show(); } else if (reciever == "Send to Bob"){ phoneNumber = "020312039"; } else if (reciever == "Send to John"){ phoneNumber = "0102308013"; } Toast.makeText(this, phoneNumber, Toast.LENGTH_LONG).show(); if (_message == ""){ Toast.makeText(this, "You have to choose a message!", Toast.LENGTH_LONG).show(); } else { Intent sms = new Intent(Intent.ACTION_SENDTO, Uri.parse("sms:" + phoneNumber)); sms.putExtra("sms_body", _message); startActivity(sms); _message = ""; } }