Buda Gavril
Buda Gavril

Reputation: 21627

android set list item custom background color

I need to set a custom color to a list item based on a property of item from adapter and I can not use a selector (condition for item to have custom color is an item property, not a selected or focused state). In getView method I set

view.setBackgroundColor(R.color.blue)

but this does not works because it doesn't matter what color I set for background, the result is the same. I tried to set background color to the layout but the result is the same. Can you please give me a clue? Thanks

Upvotes: 1

Views: 2103

Answers (3)

Asnag
Asnag

Reputation: 90

use

view.setBackground(getResources().getDrawable(R.color.Gray));

Upvotes: -1

Deimos
Deimos

Reputation: 1091

Try:

view.setBackgroundColor(getResources().getColor(R.color.blue));

Upvotes: 0

Yashwanth Kumar
Yashwanth Kumar

Reputation: 29121

use ,

view.setBackgroundResource(R.color.blue)

it will work.

Upvotes: 4

Related Questions