Reputation: 129
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
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