我的列表视图有一个自定义适配器:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
if(row == null)
{
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
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);
row.setTag(holder);
}
else
{
holder = (DataHolder)row.getTag();
}
Data data = gather[position];
holder.locationName.setText(data.locationName);
holder.locationElevation.setText(data.locationElevation);
holder.locationDistance.setText(Double.toString(data.heading));
holder.imgIcon.setImageBitmap(data.icon);
return row;
}
我的列表视图填充了项目,我只希望第一个项目具有红色背景色。当我滚动时,所有其他项目都保持有自己的颜色,但第一个项目仍然是红色。有任何想法吗?每次我尝试某些东西时,红色背景都会在我滚动时移动到其他行。