Reputation: 22023
I have created a custom view by extending AutoCompleteTextView (with a specialized function called setCursorAdapter). I am supplying a SimpleCursorAdapter and adding a FilterQueryProvider. I am using this for a list of numbers where I need the ability to search anywhere within the number for a match.
public void setCursorAdapter(final Uri uri, final String key) {
Cursor c = getContext().getContentResolver().query(uri,
new String[] { "_id", key }, null, null, key);
SimpleCursorAdapter adapter = new SimpleCursorAdapter(getContext(),
android.R.layout.simple_dropdown_item_1line, c,
new String[] { key }, new int[] { android.R.id.text1 });
this.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
((SimpleCursorAdapter) getAdapter()).getFilterQueryProvider()
.runQuery(s);
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
});
adapter.setFilterQueryProvider(new FilterQueryProvider() {
@Override
public Cursor runQuery(CharSequence constraint) {
Cursor c = getContext().getContentResolver().query(uri,
new String[] { "_id", key },
key + " LIKE '%" + constraint + "%'", null, key);
return c;
}
});
setAdapter(adapter);
}
Everything is working perfectly, until I select the value from the drop down. The value that I receive in the EditText window: android.content.ContentResolver$CursorWrapperInner@...
How do I avoid this and get my (numeric) text displayed correctly.
Thanks
Upvotes: 0
Views: 1543
Reputation: 6251
The better way is to use public void setStringConversionColumn (int stringConversionColumn)
Upvotes: 1
Reputation: 22023
Solved: SimpleCursorAdapter.converToString(cursor) -- I overrode this function to extract the value.
Thanks
Upvotes: 1