views:

16

answers:

0

Hello all

I have a problem with a filter on my listview. In fact that work pretty well with an IndexAdapter, but not with a SimpleCursorAdapter.

In the following example, if isCursor==false, the filter work pretty well but if it is == true, the filter does not work!

By the way, the adapter work pretty well.

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<String>(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);

I really do not understand where the problem might come. For information, my FilterTextWatcher is:

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); }

}

FilterTextWatcher is quite the same, but I replaced SimpleCursorAdapter with IndexAdapter

Thank a lot for any help...