Dans un billet précédent Développer sa Listview personnalisée sous android j’avais expliqué comment créer une listview personnalisée tout en java .Cette fois je vais faire pareil mais avec des fichiers xml.
Premier fichier celui de ma listview que j’appelle liste1.xml
?Download download.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</FrameLayout>
|
Deuxième fichier xml celui de chaque item que j’appelle afficheplanning.xml.
?Download download.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/date"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="date"
/>
<TextView
android:id="@+id/titre"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="recette"
/>
</LinearLayout>
|
Ensuite dans mon code java à l’endroit où je veux afficher ma listview je rajoute
?Download download.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map = new HashMap<String, String>();
map.put("date", "01/01/2009");
map.put("titre", "Jean");
mylist.add(map);
map = new HashMap<String, String>();
map.put("date", "29/12/2009");
map.put("titre", "David");
mylist.add(map);
//j'appelle le fichier de ma liste view liste1.xml
setContentView(R.layout.liste1);
mRecetteList = (ListView) findViewById(android.R.id.list);
//je crée un objet simpleAdapter avec le fichier xml des item afficheplanning.xml
SimpleAdapter mSchedule = new SimpleAdapter(this, mylist, R.layout.afficheplanning,
new String[] {"date", "titre"}, new int[] {R.id.date, R.id. titre});
//setListAdapter(new SpeechListAdapter(this));
mRecetteList.setAdapter(mSchedule);
return true;
|
résultat

aprés il ne reste plus avec les feuilles de style avec ce billet Customiser sa listview avec des feuilles de style de modifier l’apparence de la listview
A lire aussi:
- Développer sa Listview personnalisée sous android
- Customiser sa listview avec des feuilles de style
- Développez une application pour android étape 13 (Ajouter des ingredients avec une boite de dialogue personnalisée)
- Développez une application pour android étape 15 (Rajouter une listview dans mon formulaire pour aficher les ingredients)
- Synchroniser vos fichiers avec PaderSyncFTP
Une nouvelle version de notre Widget est disponible sur Android Market, Cliquez ICI ou scannez le code barre pour ne plus rater aucunes news.
© Guy pour Android-France, 2009. | Permalien | 2 commentaires | Add to del.icio.us