我正在我的时间表中创建添加主题的列表,如果主题状态等于已关闭,如何将列表项的背景颜色更改为红色。
for (DataTimetable cn : timetable) {
String section = cn.getSection();
String subjects = cn.getSubject();
String day = cn.getDay();
String timein = cn.getTimeIn();
String timeout = cn.getTimeOut();
String room = cn.getRoom();
String units = cn.getUnits();
String status = cn.getStatus();
total = total + Double.parseDouble(units);
String time = timein + " - " + timeout;
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
// adding each child node to HashMap key => value
map.put(TAG_SECTION, section);
map.put(TAG_SUBJECT, subjects);
map.put(TAG_DAY, day);
map.put(TAG_TIME, time);
map.put(TAG_ROOM, room);
map.put(TAG_UNITS, units);
map.put(TAG_STATUS, status);
// adding HashList to ArrayList
TimetableList.add(map);
}
答案 0 :(得分:0)
在ArrayAdapter的getView(...)中使用它。
if(YOUR_CONDITION){
convertView.setBackgroundColor(Color.GREEN);
}else{
convertView.setBackgroundColor(Color.YELLOW);
}