Zamani
Zamani

Reputation: 304

Check Value from mysql using android

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.

Upvotes: 0

Views: 107

Answers (2)

10s
10s

Reputation: 1699

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.

Upvotes: 2

Parag Chauhan
Parag Chauhan

Reputation: 35956

if(sold.equalIgnoreCase("0"))
{
   Log.d("checking","Inside = 0");
}else
{
   Log.d("checking","Inside = 1");
}

Upvotes: 3

Related Questions