• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps filtrarte listview with SimpleCursorAdapter

Hi,

I want filtrate my list view with SimpleCursorAdapter, i try this code not working

Code:
public class Filtrage extends ListActivity{
    DBAdapter db;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.filtrage);
    db = new DBAdapter(this);
    db.open();
    Cursor c2 = db.retrieveKidName();
    startManagingCursor(c2);
    final SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
            R.layout.list_kids, c2, new String[] { DBAdapter.kid_name },
            new int[] { R.id.txtKidNameList });
    setListAdapter(adapter);
    EditText txtFilter = (EditText) findViewById(R.id.txtFill);
    txtFilter.addTextChangedListener(new TextWatcher() {
        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) {
            if (adapter != null)
                adapter.getFilter().filter(s); 
    }
    });
}    
}
 
Back
Top Bottom