Profete162 Posted October 25, 2010 Share Posted October 25, 2010 *********************************** EDIT: Trouvé question similaire ici: http://stackoverflow.com/questions/2002607/android-how-to-text-filter-a-listview-based-on-a-simplecursoradapter Mais je comprends rien à la réponse: The system doesn't do the filtering automatically, because it wouldn't know how to filter your Cursor based on the string. You basically need to rerun the query with a new where-clause every time the user types something. If you have your own Adapter, you can easily do this by implementing runQueryOnBackgroundThread(). If you're using SimpleCursorAdapter directly, I think you need to set your own FilterQueryProvider for it. *********************************** Salut à tous, J'essaye désespérément de filtrer une liste alimentée par un SimpleCursorAdapter. Ma méthode fonctionne tres bien avec un IndexAdapter comme le montre l'exemple suivant: if(isCursor){ mCursorAdapter = new SimpleCursorAdapter(this,android.R.layout.simple_list_item_1, stationsCursor, columns, to); FilterTextWatcherCursor filterTextWatcher = new FilterTextWatcherCursor(mCursorAdapter); filterText.addTextChangedListener(filterTextWatcher); this.setListAdapter(mCursorAdapter); } else{ mIndexAdapter = new MyIndexAdapter(getApplicationContext(), R.layout.row_station_picker, elements); FilterTextWatcher filterTextWatcher = new FilterTextWatcher(mIndexAdapter); filterText.addTextChangedListener(filterTextWatcher); this.setListAdapter(mIndexAdapter); } ListView lv = getListView(); lv.setTextFilterEnabled(true); lv.setFastScrollEnabled(true); Quand je lance le programme, si isCursor== false alors tout fonctionne bien. Si par contre il == true, alors ma liste se remplit bien, mais le filtre ne fonctionne pas. Pour info, mon watcher est de la sorte: public class FilterTextWatcherCursor implements TextWatcher { private SimpleCursorAdapter adapter; public FilterTextWatcherCursor(SimpleCursorAdapter adapter) { this.adapter = adapter; } public void afterTextChanged(Editable s) { } public void beforeTextChanged(CharSequence s, int start, int count, int after) { } public void onTextChanged(CharSequence s, int start, int before, int count) { adapter.getFilter().filter(s); } } Idem pour l'autre, vous aurez compris. Donc ma question est de savoir ce qui se passe avec le SimpleCursorAdapter. Que dois-je faire pour faire fonctionner le filtre? Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.