1

I I have is a server witch is sending me a String such as "False~False~False~True~False~True~False~" or something of that nature so what I have done is I did a split on that string to the "~" so my code was String[] AString = A2MCString.split("~"); with the new string array I have I went to a cheack to see if each sections was true or false using an if else statment

if (AString[0] == "True") { Log.d("ClientActivity","Light ON"); On1.setBackgroundResource(R.drawable.selected_on); } else Log.d("ClientActivity","Light OFF"); 

however even when the server send me true in the first part of my string array the array still bounces to else saying that it is false even though it was true? Any help for my problem thanks!

1 Answer 1

5

When comparing strings in java you must use the equals method. In your case something like

if (AString[0].equals("True")) { Log.d("ClientActivity","Light ON"); On1.setBackgroundResource(R.drawable.selected_on); } else Log.d("ClientActivity","Light OFF"); 

When using the == operator on objects (in java a string is an object), it is comparing if the two object references point to the same object.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.