0

I have a table which has a field called Sold , in that field i store 0 and 1. So 1 means sold and 0 mean Available.

K, my problem is that ,I want to change 0 to available and 1 to sold when i diplay information into my emulator , here what i tried but it returning sold even though i have 0 in my database :

if (sold.length()==0){

    Log.d("checking","Inside = 0");

    val = "Available";}

    else if (sold.length()>0)

        Log.d("checking","Inside = 1");
        val = "Sold

And sold contains a value from a database.

please help to change 0 to Available and 1 to Sold.

2 Answers 2

3
if(sold.equalIgnoreCase("0"))
{
   Log.d("checking","Inside = 0");
}else
{
   Log.d("checking","Inside = 1");
}
Sign up to request clarification or add additional context in comments.

2 Comments

You are a King parag..tanx alot :)
Its my pleasure that i useful to u.
2

The sold.length you have there is the actual length of the String representation "sold" that you are using. Meaning that if you have the word "some" this .length() equals 4.

So in your snippet the sold variable is the "0" or "1" respectively so the sold.length() always equals to 1. Try to cast the String variable into an Integer and make the comparison or even better try to make the variable into Integer from the beginning.

1 Comment

Tanx dude, but parag just gave me what i was looking for, but atleast i also gave you one for making me understand

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.