我阅读了很多其他帖子,但是大多数,如果不是所有帖子都告诉你覆盖其中一个方法,然后改变背景。我想在ListView Adapter类之外更改它,所以我尝试这样做。它似乎不起作用。然而,我确实得到了这个对象,它不会改变它的背景。
RelativeLayout item;
item = (RelativeLayout) listView.getAdapter().getView(0, null, listView);
item.setBackgroundColor(Color.YELLOW);
谢谢。
答案 0 :(得分:1)
找到最近的时间将其保存在变量中并调用adapter.notifyDataSetChanged()
public View getView(int position, View convertView, ViewGroup parent){
if(time is nerest time) {
convertView. setBackgroundColor(Color. YELLOW)
} else {
convertView. setBackgroundColor("default color")
}
}