setBackground in View cannot be applied to (int)

loveubae :

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);
forpas :

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);

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=131569&siteId=1