首先该activity是继承listactivity,因为每次返回时都会把之前的颜色变回默认的颜色,所以干脆每次都把list的每一个item的((TextView)ll.getChildAt(1)).getText().equals("失败")都设置为红色,“成功”一样。
for(int i=0; i< this.getListView().getCount(); i++){
LinearLayout ll = (LinearLayout)getInstance().getListView().getChildAt(i);
if(ll != null && ((TextView)ll.getChildAt(1)).getText().equals("失败")){
((TextView)ll.getChildAt(1)).setTextColor(Color.RED);
}else if(ll != null && ((TextView)ll.getChildAt(1)).getText().equals("成功")){
((TextView)ll.getChildAt(1)).setTextColor(Color.GREEN);
}
}
后来发现这个还是有问题,首先就要了解listview的显示原理,我的感觉类似于循环“队列”,从而到达节省内存资源,即如listview被下滚动后第一行失去屏幕显示,它会被系统循环利用来补充到最后一行显示。上滚也一样。
解决上面的问题还是自己重写adapter,在getView方法中实现想要的效果。
listAdapter