Bonsoir à tous,

Je rencontre un problème avec ListView dès que je met un bouton dans mon listView ben je ne passe plus dans la méthode "onItemClick" est si je change le button en TextView çelà fonctionne je ne vois pas pourquoi ...

Le layout:

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
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >
 
       <ImageView
        android:id="@+id/img"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:padding="10sp"
        android:contentDescription="@string/desc_logo"
        />
 
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="0dp"
        android:textIsSelectable="false"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:paddingLeft="10sp"
        android:layout_weight="1"
        >
 
        <Button android:id="@+id/txt_ardoise"
            android:textIsSelectable="false"
            android:clickable="true"
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"
             android:background="@drawable/ardoise"
             android:textSize="16sp"
             android:textColor="#fff"
             android:textStyle="bold"
             />
 
        <TextView android:id="@+id/description_acceuil"
            android:textIsSelectable="false"
             android:layout_width="fill_parent"
             android:layout_height="fill_parent"
             android:textSize="12sp"
             android:textColor="#333"
             />
 
    </LinearLayout>
 
   <ImageView
        android:id="@+id/img_arrow"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:padding="10sp"
        android:src="@drawable/next"
        android:contentDescription="@string/desc_fleche"
        />
 
</LinearLayout>
Le oncreate de l'activité:

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
@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
 
    setContentView(R.layout.activity_around_me);
 
    listMenuAroundMe = (ListView)findViewById(R.id.around_me_list_item);
 
 
    //Création de la ArrayList qui nous permettra de remplire la listView
    ArrayList<HashMap<String, String>> listItem = new ArrayList<HashMap<String, String>>();
 
    //On déclare la HashMap qui contiendra les informations pour un item
    HashMap<String, String> map;
 
 
 
    map = new HashMap<String, String>();
    map.put("id", "1");
    map.put("txt_ardoise", "Restzu");
    map.put("description", "plat a 20€");
    map.put("img", String.valueOf(R.drawable.ic_launcher));
    listItem.add(map);
 
 
    HomeList adapter = new HomeList(this.getBaseContext(), listItem, R.layout.item_menu_2,
            new String[] {"img", "txt_ardoise", "description"}, new int[] {R.id.img, R.id.txt_ardoise, R.id.description_acceuil});
 
    listMenuAroundMe.setClickable(true);
    listMenuAroundMe.setFocusable(true);
 
    listMenuAroundMe.setAdapter(adapter);
 
 
    listMenuAroundMe.setOnItemClickListener(this);
}
Le methode onItemClick

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
 
@Override
    public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3)
    {
 
 
        @SuppressWarnings("unchecked")
        HashMap<String, String> map = (HashMap<String, String>) listMenuAroundMe.getItemAtPosition(position);
 
        String id = map.get("id");
Log.i("", "ID = " +id );
}
merci