Good afternoon. I have an AutoCompleteTextView app in an Android app and it works fine. However, I noticed that sentences are based on the first character of the substrings of the list provided in AutoCompleteTextView. However, this is in itself, but I want it to also show elements that contain user input.
For example, let me use this list:
- Fat
- Bad Wolf
- Cybermen
- Far away
Input in adwill offer Adipose, however I also want to offer Bad Wolf, as it contains adin Bad. This will not happen, because AutoCompleteTextView looks only at the beginning of the substrings (the substring is separated by a space) in the list items, and not inside these substrings.
Is there a way to get AutoCompleteTextViews to suggest elements that contain input text, regardless of where the text falls inside the list item?
Thanks for any help.
EDIT / UPDATE
Please see psklink below. I tried to implement the same solution as follows.
The logic from what I suggested is that it should be used SimpleCursorAdapter, not general ArrayAdater. Then I created FilterQueryProviderfor SimpleCursorAdapter. Using the method runQuery FilterQueryProvider, I can now start the filter algorithm by searching my input list for user restrictions. Here is the code:
AutoCompleteTextView search = (AutoCompleteTextView) findViewById(R.id.actvCatalogueSearch);
search.setThreshold(1);
int[] to = { android.R.id.text1 };
SimpleCursorAdapter cursorAdapter = new SimpleCursorAdapter(this,
android.R.layout.simple_dropdown_item_1line, null, pdflist, to, 0);
cursorAdapter.setStringConversionColumn(1);
FilterQueryProvider provider = new FilterQueryProvider(){
@Override
public Cursor runQuery(CharSequence constraint) {
Log.d("hi", "runQuery constraint: " + constraint);
if (constraint == null) {
return null;
}
String[] columnNames = { Columns._ID, "name" };
MatrixCursor c = new MatrixCursor(columnNames);
try {
for (int i = 0; i < pdflist.length; i++) {
if(pdflist[i].contains(constraint)){
c.newRow().add(i).add(pdflist[i]);
}
}
} catch (Exception e) {
e.printStackTrace();
}
return c;
}
};
cursorAdapter.setFilterQueryProvider(provider);
search.setAdapter(cursorAdapter);
The Log for statement is shown runQuery constraint, after which the application crashes, and I get this error in my logcat:
requesting column name with table name
.....
java.lang.IllegalArugmentException: column <first element of array here> does not exist
logCat jar, . , , , - , String[] columnNames MatrixCursor.
- ? - , , .
. .