Bonjour a tous, je debute sous android et je cherche à créer une liste de vues personnaliser, mais j'ai un peu de mal à comprendre comment tout cela fonctionne et la seul chose que je parviens à obtenir c'est une page blanche.

Voici mon code:

Tout d'abord le xml:
le fichier activity.xml:

Code XML : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/vuePrincipal">
 
    <ListView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/listView"/>
 
</LinearLayout>


le fichier vue.xml:

Code XML : Sélectionner tout - Visualiser dans une fenêtre à part
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
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/vueList">
 
    <TextView
        android:id="@+id/nomPrenom"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
 
    <TextView
        android:id="@+id/numTel"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>
 
    <ImageView
        android:id="@+id/imageView"
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:layout_marginLeft="6dp"
        android:layout_marginRight="6dp"
        android:layout_marginTop="5dp"
        android:layout_marginBottom="5dp"
        android:contentDescription="image"/>
</LinearLayout>

ensuite le code java:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package fr.adaptateurperso;
 
import android.app.Activity;
import android.os.Bundle;
import android.widget.ListView;
 
public class AdaptateurPerso extends Activity
{
    protected void onCreat(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        ListView list = (ListView) findViewById(R.id.listView);
 
        int vue = R.layout.activity;
        setContentView(vue);
 
        RepertoireAdapter adapter = new RepertoireAdapter(this);
        list.setAdapter(adapter);
    }
}
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package fr.adaptateurperso;
 
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
 
public class RepertoireAdapter extends BaseAdapter
{
    private int[] tab_images_pour_la_liste = {
            R.drawable.maman, R.drawable.mami,
            R.drawable.manif, R.drawable.papi, R.drawable.phare};
 
    private String[] valeurNom = new String[] { "maman",
            "mamie", "manif", "papi", "phare"},
                     valeurNum = new String[]{"111111", "2222222", "3333333", "4444444", "55555555"};
 
    private Context contexte;
 
    public RepertoireAdapter(Context contexte)
    {
        super();
        contexte = contexte;
    }
 
    @Override
    public int getCount()
    {
        return tab_images_pour_la_liste.length;
    }
 
    @Override
    public Object getItem(int position)
    {
        return tab_images_pour_la_liste[position];
    }
 
    @Override
    public long getItemId(int position)
    {
        return position;
    }
 
 
    LayoutInflater inflater;
 
    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        ViewHolder holder = null;
 
        if(convertView == null)
        {
            convertView = inflater.inflate(R.layout.vue, null);
 
            holder = new ViewHolder();
            holder.nom = (TextView) convertView.findViewById(R.id.nomPrenom);
            holder.num = (TextView) convertView.findViewById((R.id.numTel));
            holder.photo = (ImageView) convertView.findViewById(R.id.imageView);
 
            convertView.setTag(holder);
        }
        else
        {
            holder.nom.setText(valeurNom[position]);
            holder.num.setText(valeurNum[position]);
            holder.photo.setImageResource(tab_images_pour_la_liste[position]);
        }
 
        return convertView;
    }
 
    static class ViewHolder
    {
        public TextView nom,
                        num;
        public ImageView photo;
    }
}
Voila, un grand merci à celui ou celle qui saura m'explique comment créer un adaptateur personnalisé correctement.