I am changing row background color if the fetching data from database size is more than zero as gray otherwise not changing anything.For first item i am setting default folder and remaining as list names for these lists also setting background same like above.When I scroll the list all the bacground positions are changed..I know that positions are changing while scrolling.How to solve this one?
First position should be always Default List. I am giving code snippet for understanding purpose
if(position == 0)
{
holder.listName.setText("Default List");
int c = //getting database table size
if(c == 0 )
{
holder.rowLayout.setBackgroundColor(Color.GRAY);
}
开发者_StackOverflow}
else
{
list =//getting lists from database(different table)
if(list!=null)
{
holder.listName.setText(list.getListName());
}
if(list size==0)
{
holder.rowLayout.setBackgroundColor(Color.GRAY);
}
}
The ListItem recycled when you scroll the List that is why you are getting random background for ListItem. You have to change background of ListItem to it default color.
as follows..
if(list size==0)
holder.rowLayout.setBackgroundColor(Color.GRAY);
else
holder.rowLayout.setBackgroundColor(Color.BLACK);
精彩评论