Android:Listview行背景颜色在滚动中更改

Android:Listview行背景颜色在滚动中更改,android,Android,这是我的密码 public View getDropDownView(int position, View view, ViewGroup parent) { ViewHolder holder = null; if(view==null) { view= inflater.inflate(R.layout.citylist, parent, false); holder

这是我的密码

    public View getDropDownView(int position, View view, ViewGroup parent) {

        ViewHolder holder = null;  

        if(view==null)
        {
            view= inflater.inflate(R.layout.citylist, parent, false);       
            holder=new ViewHolder();
            holder.txtTitle = (TextView) view.findViewById(R.id.tv);    
            holder.txtTitle.setTextSize(TypedValue.COMPLEX_UNIT_DIP,db.getSettings().getInt(15)-3);
            holder.txtTitle.setPadding(10, 10, 10, 10);                     
            view.setTag(holder);        
        }
        else{       
            holder=(ViewHolder)view.getTag();       
        }

        holder.txtTitle.setText(data.get(position));
        if(position % 2 == 0)view.setBackgroundColor(Color.rgb(224, 224, 235));
        return view;
   }

当我滚动偶数行上的颜色也出现在奇数行帮助中时,列表中的视图将被回收。也就是说,滚动到熨平板外部的项目视图在滚动到屏幕的项目中重复使用。因此,您需要将奇数项设置为正常颜色,如下所示

if(position % 2 == 0)view.setBackgroundColor(Color.rgb(224, 224, 235));
if(position % 2 == 1)view.setBackgroundColor(The normal color you should set);
改变

if(位置%2==0)view.setBackgroundColor(Color.rgb(224224235))

view.setBackgroundColor(位置&1==0?Color.rgb(224224235):android.R.Color.transparent)