Bonjour tout le monde,
J'ai réussi à faire une recherche sur une ListView qui marche très bien :
Cependant, quand je clique sur un item, je dois récupérer le rang dans la liste l pour le passer en paramètre à l'activité déclenché :
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 // initialisation de la liste grâce au message passé this.l = new ArrayList<String>(); this.l = this.initialiserListe(message); Collections.sort(l); // création de la vue this.arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, l); vue = (ListView) findViewById(R.id.listView); vue.setAdapter(arrayAdapter); inputSearch = (EditText) findViewById(R.id.inputSearch); /** * Enabling Search Filter * */ inputSearch.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) { EnglishWordList.this.arrayAdapter.getFilter().filter(cs); } @Override public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {} @Override public void afterTextChanged(Editable arg0) {} });
Cependant le l.get(position) me renvoit 0, je ne sais pas comment faire pour prendre le rang de l'élément afficher pendant ou après un search. Une idée ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 vue.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int position,long id) { Intent intent = new Intent(EnglishWordList.this, DisplayDefinition.class); String m = EnglishWordList.this.l.get(position); intent.putExtra(EXTRA_MESSAGE_ANGLAIS, m); startActivity(intent); } });
Partager