Bonsoir,
Je suis actuellement bloqué avec une listview, j'obtiens bien les données escomptées grâce au code suivant mais je n'arrive pas à cliquer sur un item pour afficher le nom de l'hôtel par exemple. Pouvez-vous m'aider
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 @Override public void onClick(View v){ switch (v.getId()) { case R.id.retour: Intent intent = new Intent(this, MainActivity.class); startActivity(intent); break; case R.id.recherchons: arrayList.clear(); String choixcategorie = Categorie.getSelectedItem().toString(); String choixville = Ville.getSelectedItem().toString(); String lechoix = ""; Choixnom = (EditText) findViewById(R.id.choixx); lechoix = Choixnom.getText().toString(); if (lechoix != "" & choixcategorie != "Categorie" & choixville != "Ville") { try { Cursor cursor = dbHelper.QueryData("select id,type,nom from my_database" + " where upper(nom) like upper('" + lechoix + "%') and commune =" + "'" + choixville + "'" + " and type=" + "'" + choixcategorie + "'"); if (cursor != null) { if (cursor.moveToFirst()) { do { Item item = new Item(); //item.setId(cursor.getString(0)); item.setType(cursor.getString(1)); item.setNom(cursor.getString(2)); arrayList.add(item); /*ImageView img = (ImageView) findViewById(R.id.imagedelacategorie); img.setImageResource(R.drawable.ic_commerce);*/ } while (cursor.moveToNext()); } } } catch (SQLException e) { } adapter = new Adapter(this, R.layout.custom_list_item, arrayList); listView = (ListView) findViewById(R.id.list_item); listView.setAdapter(adapter); adapter.notifyDataSetChanged(); /* ne marche pas listView.setOnItemClickListener(new OnItemClickListener() { @Override @SuppressWarnings("unchecked") public void onItemClick(AdapterView<?> a, View v, int position, long id) { HashMap<String, String> map = (HashMap<String, String>) listView.getItemAtPosition(position); AlertDialog.Builder adb = new AlertDialog.Builder(ButtonRecherche.this); adb.setTitle("Sélection Item"); adb.setMessage("Votre choix : ");//+map.get("titre") adb.setPositiveButton("Ok", null); adb.show(); } });*/
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 public class Adapter extends ArrayAdapter<Item> { private Activity activity; int id; ArrayList<Item> items; public Adapter(Activity context, int resource, ArrayList<Item> objects) { super(context, resource, objects); this.activity=context; this.id=resource; this.items=objects; } @Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView==null){ LayoutInflater inflater=activity.getLayoutInflater(); convertView=inflater.inflate(id,null); } Item item=items.get(position); TextView tv_type= (TextView) convertView.findViewById(R.id.tv_type); TextView tv_nom= (TextView) convertView.findViewById(R.id.tv_nom); tv_type.setText(item.getType()); tv_nom.setText(item.getNom()); return convertView; } }
Partager