Monday, 26 August 2013

Autocomplete suggests text multiple times

Autocomplete suggests text multiple times

I'm novice programmer and I have problem with autocomplete. At this moment
it suggest text when it's in database, but when I add multiple records
with same text it suggest same text multiple times. Any idea what should I
do?
Here's fragment of code:
adapter.setCursorToStringConverter(new CursorToStringConverter() {
public String convertToString(android.database.Cursor cursor) {
final int columnIndex =
cursor.getColumnIndexOrThrow(DatabaseHelper.LESSONS_SUBJECT);
final String str = cursor.getString(columnIndex);
return str;
}
});
adapter.setFilterQueryProvider(new FilterQueryProvider() {
public Cursor runQuery(CharSequence constraint) {
String[] projection = new String[] {
DatabaseHelper.LESSONS_ID, DatabaseHelper.LESSONS_SUBJECT };
String selection = DatabaseHelper.LESSONS_SUBJECT + " LIKE '"
+ constraint + "%'";
Cursor cursor =
getActivity().getContentResolver().query(DatabaseManager.CONTENT_URI_LESSONS,
projection,
selection, null, null);
return cursor;
}
});
Feel free to ask for more code if you need it to solve this problem.
Screenshot:

No comments:

Post a Comment