Propriété de Albiri Sigue
customer 27921 at Fri Mar 11 19:19:45 +0100 2011
Chapitre 8
Widgets de sélection 79
edit.setAdapter(new ArrayAdapter(this,
android.R.layout.simple_dropdown_item_1line,
items));
}
public void onTextChanged(CharSequence s, int start, int before,
int count) {
selection.setText(edit.getText());
}
public void beforeTextChanged(CharSequence s, int start,
int count, int after) {
// imposée par l’interface, mais inutilisée
}
public void afterTextChanged(Editable s) {
// imposée par l’interface, mais inutilisée
}
}
Cette fois-ci, notre activité implémente l’interface TextWatcher, ce qui signifie que nos
méthodes de rappel doivent se nommer onTextChanged() et beforeTextChanged(). Ici,
seule la première nous intéresse : elle modifie le label de sélection pour qu’il reflète le
choix courant du champ AutoCompleteTextView.
Les Figures 8.8, 8.9 et 8.10 montrent ce qu’affiche cette application.
Figure 8.8
L’application AutoCompleteDemo après
son démarrage.
Livre Android.book Page 79 Dimanche, 8. novembre 2009 12:23 12
Précédent

- 94/391

Suivant