I am very much an Android newbie and I have built a simple RSS reader application based around the free IBM android RSS tutorial. I would like to change the background color of each row if the category of that row is equal to a particular String.
I wrote the following “for loop” which discovers the category of each item and runs an if statement should that category be equal to “News”. At the moment the background colour of the entire listview gets changed as soon as a feed is supplied with a News category.
Does anyone out there feel like helping out a beginner?
for(int i = 0; i < feed.getItemCount(); i++)
{
if (feed.getItem(i).getCategory().equals("News"))
{
ListView.setBackgroundColor(0x77ee0044);
}
}
You’re going to need to do this inside the
getView()method of your adapter.Before you return the view in getView(), you can call setBackgroundColor() on the view or use one of the other
setBackgroundFoo()methods.Edit – given your code, when you create your Adapter, try:
This overrides getView() to adjust the background of your list item views properly.