@OverrIDepublic 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;}
但是,当滚动列表时,另一个随机项目的背景颜色会发生变化.我必须做什么.如何控制列表视图中每个位置的项目.以上代码仅适用于第一行.我对吗?
解决方法 试试这个@OverrIDe public VIEw getVIEw(int position,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());//**********SET ALSO YOUR DEFAulT BACKGROUND HERE******** like// holder.txtVIEwDescription.setBackgroundResource(R.color.DEFAulcolor); holder.txtholder.setBackgroundResource(R.color.DEFAulcolor); holder.img.setimageResource(R.drawable.defalut_image);//**********SET ALSO YOUR DEFAulT BACKGROUND HERE******** ok// //------------------ 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; }总结
以上是内存溢出为你收集整理的滚动时Android-Listview项目背景颜色发生变化全部内容,希望文章能够帮你解决滚动时Android-Listview项目背景颜色发生变化所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)