我通过扩展AutoCompleteTextView(使用名为setCursorAdapter的专用函数)创建了一个自定义视图。我提供SimpleCursorAdapter并添加FilterQueryProvider。我使用它来获取一个数字列表,我需要能够在数字内的任何地方搜索匹配。
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);
}
一切正常,直到我从下拉列表中选择值。我在EditText窗口中收到的值:android.content.ContentResolver $ CursorWrapperInner @ ...
如何避免这种情况并正确显示我的(数字)文本。
由于
答案 0 :(得分:1)
Solved:SimpleCursorAdapter.converToString(cursor) - 我重写了这个函数来提取值。
由于
答案 1 :(得分:1)