Changer style d'un TextView en fonction de son contenu
Bonjour à tous,
J'aimerais faire en sorte que le style d'un TextView qui est lui meme dans une ListView puisse changer de style en fonction de son contenu (le contenu peut etre " " (un espace) ou du texte.
Le code XML
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| <?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TableLayout
android:id="@+id/blocCheck"
android:layout_marginTop="15px"
android:layout_marginBottom="15px"
android:layout_marginRight="15px"
android:layout_marginLeft="15px"
android:layout_height="wrap_content"
android:layout_width="fill_parent" >
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center_vertical">
<TextView
android:id="@+id/date_bar"
android:gravity="center_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:textStyle="bold"
android:layout_gravity="left" />
</LinearLayout>
</TableRow>
BlaBla... |
Le code Java :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| while(!cursor.isAfterLast()){
map = new HashMap<String, String>();
map.put("id",Integer.toString(cursor.getInt(0)));
if(cursor.getString(9).compareTo(dateAffichage)!=0){
String textBarreDate="";
if(cursor.getString(9).compareTo(getTodayFormattedDate())==0){
textBarreDate="Aujourd'hui\n"+getTodayFormattedDate();
}else if(cursor.getString(9).compareTo(getTomorrowFormattedDate())==0){
textBarreDate="Demain\n"+getTomorrowFormattedDate();
}else{
textBarreDate=cursor.getString(9);
}
map.put("date_bar",textBarreDate);
}else{
map.put("date_bar","");
}
listItem.add(map);
cursor.moveToNext();
}
SimpleAdapter mSchedule = new SimpleAdapter (this.getBaseContext(),listItem,R.layout.activity_main_list,new String[] {"date_bar", "type", "chaine", "code", "nom"},new int[] {R.id.date_bar, R.id.type,R.id.chaine,R.id.code,R.id.nom });
listeViewGeneral.setAdapter(mSchedule); |
Alors à moins qu'on puisse glisser des formules conditionnelles dans le XML...
Ma question : comment et à quel moment je peux lui dire que je veux qu'il mette le TextView dans un autre style (sans que cela s'applique à tous les TextView qui portent le même id) ?
Merci par avance