I am trying to set a condition and set true or false as follows but it returns false all the time.
boolean checked = (categoriesCursor.getString(3) == "1") ? true
: false;
Log.i("Nomad",categoriesCursor.getString(3)+ " "+checked);
When i try to output the values i get the following.
01-12 00:05:38.072: I/Nomad(23625): 1 false
01-12 00:05:38.072: I/Nomad(23625): 1 false
01-12 00:05:38.072: I/Nomad(23625): 1 false
01-12 00:05:38.072: I/Nomad(23625): 1 false
01-12 00:05:38.072: I/Nomad(23625): 1 false
01-12 00:05:38.072: I/Nomad(23625): 0 false
01-12 00:05:38.072: I/Nomad(23625): 0 false
It returns
falseall the time because you are comparing references, not strings. You probably meant this instead:Which happens to be equivalent to this:
And in case
categoriesCursor.getString(3)may benull, you will be safer doing this instead: