2013-10-15 5 views
0

Je crée une liste de sujets ajoutés dans mon emploi du temps et comment puis-je changer la couleur de fond de l'élément de la liste en rouge si le statut du sujet est égal à fermé.Changer la couleur de fond 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

Avez-vous un ArrayAdapter? Pls jeter un oeil à ces tutoriels http://www.vogella.com/articles/AndroidListView/article.html –

+0

oui. mais je veux juste savoir comment puis-je changer la couleur d'arrière-plan de listitem si le statut du sujet est égal à fermer sans sélectionner – user2692273

+0

voir ma réponse, je ne sais pas quel est votre problème –

Répondre

0

Dans votre getView (...) dans votre ArrayAdapter, utilisez ceci.

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

pouvez-vous me donner un échantillon complet de getView et comment puis-je l'utiliser dans mes codes – user2692273

+0

plaese jeter un oeil à ce tut Point 10 http://www.vogella.com/articles/AndroidListView/article.html –

Questions connexes