Take the 2-minute tour ×

I have a custom adapter for my listview:

    View row = convertView;

    if(row == null)
        row = inflater.inflate(layoutResourceId, parent, false);

        holder = new DataHolder();
        holder.imgIcon = (ImageView)row.findViewById(R.id.imgIcon);
        holder.locationName = (TextView)row.findViewById(R.id.locationName);
        holder.locationElevation = (TextView)row.findViewById(R.id.lcoationElevation);
        holder.locationDistance = (TextView)row.findViewById(R.id.locationDistance);
        holder = (DataHolder)row.getTag();

    Data data = gather[position];

    return row;

My listview is populated with items, I just want the very first item to have a Red background color. As I scroll all the other items remain there own color, but the very first item is still red. Any ideas? Everytime I try something the red background moves around to the other rows as I scroll.

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted


I'm guessing that you didn't have an else clause. Each row layout is reused by the adapter to save resources. So if you change a value in a layout it will carry over the next time this particular layout is recycled. Simply add an else statement return the recycled View back to it's default state:

if(position == 0)
    row.setBackgroundColor(0x00000000); // Transparent

(If the background was a specific color, instead of transparent, you'll need to change that value.)

share|improve this answer
add comment

Your Answer


