Answer the question
In order to leave comments, you need to log in
Android: AutoCompleteTextView + SimpleCursorAdapter. Data filtering, is it possible?
Good day.
The idea is this. There is a DB. Records from the database are displayed in the ListView. It is necessary to implement a "smart search" in the list, that is, you enter characters in a text field, a hint appears (a list of fields that matched the request). Decided to try AutoCompleteTextView.
in onCreate() activity create adapter and assign it to ListView and AutoCompleteTextView
...
editQuery = (AutoCompleteTextView)this.findViewById(R.id.editQuery);
listView = (ListView)this.findViewById(R.id.listView);
// создааем адаптер и настраиваем список
SimpleCursorAdapter scAdapter = new SimpleCursorAdapter(this, R.layout.item, cursor, from, to);
scAdapter.setCursorToStringConverter(new SimpleCursorAdapter.CursorToStringConverter()
{
public CharSequence convertToString(Cursor cursor)
{
return cursor.getString(NAME_COLUMN); // return name of desiase
}
});
listView.setAdapter(scAdapter);
editQuery.setAdapter(scAdapter);
listView.setOnItemClickListener(this);
editQuery.setOnItemClickListener(this);
...
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question