Search code examples
javaandroidandroid-studioparse-platformback4app

How to get string from Parse Server in Android


I use Back4app Parse Server for backend.

I retrieve data from this server well. But I can't use 'if else statement'.

E.g,

If the advertisement is for sale, the advertisement price should appear on price textview,

if the advertisement is a gift, the "gift" text should appear instead of the advertisement price.

But it shows always advertisement price even if ad is gift.

It goes to else statement everytime.

Where did I make mistake ?

if (adObj.getString(Configs.ADS_CONDITION) == "Gift"){
            holder.priceTV.setText("Gift");
}
else {
holder.priceTV.setText(adObj.getString(Configs.ADS_CURRENCY) + " " + String.valueOf(adObj.getNumber(Configs.ADS_PRICE)));
}

Solution

  • Comparing strings in Java is done using the equals method.

    Example:

    String variable = "a";
    "a".equals(variable) // true