Akaev Dzhalal
Akaev Dzhalal

Reputation: 129

setBackground in View cannot be applied to (int)

Trying to set the background to the text. The problem is the next error - setBackground in View cannot be applied to (int)

Here is my code

if (restaurants.get(position).getOffers() != null) {

        viewHolder.offerOrNew.setText("%");
        viewHolder.offerOrNew.setBackground(R.drawable.offers_style);
    }

The error is caused accordingly in this line

viewHolder.offerOrNew.setBackground(R.drawable.offers_style);

Upvotes: 3

Views: 3308

Answers (1)

forpas
forpas

Reputation: 164064

From View.java the method setBackground() signature is this:

public void setBackground(Drawable background)

so the argument must be a Drawable object and not a resource id.
You can use setBackgroundResource() instead:

viewHolder.offerOrNew.setBackgroundResource(R.drawable.offers_style);

Upvotes: 6

Related Questions