K want to compare two strings but the equals()
method always return true , so the if statement always runs. why this happens?
resultString = "Test1";
String CompleteString = "Test";
if(CompleteString.equals(resultString));
{
rowView.setBackgroundResource(R.color.listselect_red);
}
if(CompleteString.equals(resultString));
<-- remove the ;
Your code is the equivalent to :
if(CompleteString.equals(resultString))
{
//empty block
}
{
rowView.setBackgroundResource(R.color.listselect_red);
}
So if equals returns true, the empty block will be executed, and after the second block will be always executed whatever the if was false
or true
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With