Vous êtes sur la page 1sur 5

Youssef Missaoui High-Tech

Android
TP2


Youssef Missaoui High-Tech




Personnaliser une ListView

Les ListView sont trs utiles pour afficher clairement un grand nombre de donnes.
anmoins insrer une simple ListView dans son application Android peut ne pas con!enir
esthti"uement parlant. ous allons donc !oir comment personnaliser une ListView.

Le but de ce TP est d#arri!er au rsultat sui!ant $











Youssef Missaoui High-Tech


Code XML

ous allons d#abord crer une ListView dans le fichier activity_main.xml% il n#& a aucune
difficult pour cette tape.

<?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"
>

<ListView
android:id="@+id/listviewperso"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>

</LinearLayout>

Maintenant crons un nou!eau fichier 'ML "ue l#on !a appeler affichageitem.xml% "ui
comme son nom l#indi"ue !a nous permettre de crer la !ue "ui affichera l#item dans la
ListView. (oici un petit schma montrant comment nous allons construire notre !ue
affichageitem$



)onc !oici le fichier affichageitem.*ml correspondant + ce schma $

<?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"
>

<ImageView
android:id="@+id/img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
Youssef Missaoui High-Tech
android:padding="10px"
/>

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:paddingLeft="10px"
android:layout_weight="1"
>

<TextView android:id="@+id/titre"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textSize="16px"
android:textStyle="bold"
/>

<TextView android:id="@+id/description"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>

</LinearLayout>

</LinearLayout>

Code JAVA



Youssef Missaoui High-Tech

Vous aimerez peut-être aussi