2013-10-15 318 views
0

我在我的时间表中创建了添加主题的列表,如果主题状态等于关闭,我如何将列表项的背景颜色更改为红色。更改Listitem背景颜色

 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

你有一个ArrayAdapter?请看看这些教程http://www.vogella.com/articles/AndroidListView/article.html –

+0

是的。但我只想知道,如何改变listitem的背景颜色,如果主题状态等于关闭没有选择 – user2692273

+0

看到我的答案,我做网获取你的问题是 –

回答

0

在你的ArrayView中的getView(...)中使用这个。

if(YOUR_CONDITION){ 
    convertView.setBackgroundColor(Color.GREEN); 
}else{ 
    convertView.setBackgroundColor(Color.YELLOW); 
} 
+0

你可以给我一个完整的getView样本,以及如何在代码中使用 – user2692273

+0

plaese看看这个tut Point 10 http://www.vogella.com/articles/AndroidListView/article.html –