我的ListView
包含两个Textviews
. 在一行中,第一个用于名称,第二个用于结果。我需要TextView
根据结果更改结果的背景颜色。就像如果通过,那么TextView
当失败时结果TextView
颜色将为绿色,结果颜色将为红色。我的ListView
. 我试过这样
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ViewHolder holder;
if(convertView==null)
{
holder = new ViewHolder();
convertView = inflater.inflate(R.layout.items, null);
holder.imgViewLogo = (ImageView) convertView.findViewById(R.id.imgViewLogo);
holder.txtViewTitle = (TextView) convertView.findViewById(R.id.txtViewTitle);
holder.txtViewDescription = (TextView) convertView.findViewById(R.id.txtViewDescription);
holder.txtholder = (TextView) convertView.findViewById(R.id.holder1);
holder.img = (ImageView) convertView.findViewById(R.id.temperrr);
convertView.setTag(holder);
}
else
holder=(ViewHolder)convertView.getTag();
ItemBean bean = (ItemBean) itemList.get(position);
holder.imgViewLogo.setImageResource(bean.getImage());
holder.txtViewTitle.setText(bean.getTitle());
holder.txtViewDescription.setText(bean.getDescription());
//------------------
if (position==0)
{
if(GridviewAdapter.glu>=81)
{
holder.img.setImageResource(R.drawable.red_arrow);
holder.txtViewDescription.setBackgroundResource(R.color.resultred);
holder.txtholder.setBackgroundResource(R.color.resultred);
}
else if (GridviewAdapter.glu==79||GridviewAdapter.glu==80)
{
holder.img.setImageResource(R.drawable.orange_arrow);
holder.txtViewDescription.setBackgroundResource(R.color.resultoren);
holder.txtholder.setBackgroundResource(R.color.resultoren);
}
else
{
holder.img.setImageResource(R.drawable.resultarrawnocolor);
holder.txtViewDescription.setBackgroundResource(0);
holder.txtholder.setBackgroundResource(0);
}
}
holder.img.setImageResource(R.drawable.resultarrawnocolor);
return convertView;
}
但是,当滚动列表时,另一个随机项目的背景颜色发生变化。我必须做什么。?如何控制列表视图中每个位置的项目。上面的代码仅适用于第一行。我对吗?