sqlite + adapter + OnItemClick
Bonjour, j'ai un problème avec un bout de mon code.
J'ai créé une base de données, l'utilisateur en cliquant sur un bouton me renseigne son id et change la clause where.
Je récupere le résultat de la requete dans un curseur, puis l'affiche dans une listView. J'aimerai pouvoir rajouter un setOnItemClickListener(), mais le probléme est que je n'instancie jamais une ListView donc impossible d'utiliser la fonction.
L'autre possibilité étant d'ajouter un bouton pour chaque item mais là-aussi je coince.
(j'ai pas du tout comprendre en faisant le tuto...)
Voici mon code:
La fonction avec le curseur et affichage list:
Code:
1 2 3 4 5 6 7 8
| public void DataBind(String type){
Cursor c = db.getBackStoreList(type);
startManagingCursor(c);
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
(R.layout.list_item),c,new String[]{"type","nom","adresse","latitude","longitude"},
new int[]{R.id.TextType,R.id.TextName,R.id.TextAdresse,R.id.TextLatitude,R.id.TextLongitude});
setListAdapter(adapter);
} |
La layout utilisé dans la fonction:
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 40 41 42 43
| <?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/TextType"
android:textStyle="bold"
android:textColor="#FFFFFFFF"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/TextName"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/TextAdresse"
android:textColor="#FF808080"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/TextLatitude"
android:textColor="#FF808080"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/TextLongitude"
android:textColor="#FF808080"
/>
</LinearLayout> |
Et enfin le layout de ma classe:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| <?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:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@android:id/list"
/>
</LinearLayout> |
De plus quel est la différence entre : android:id="@android:id/list"
et android:id="@+id/list"