Android 使用AutoCompleteTextView将光标自定义为文本

Android 使用AutoCompleteTextView将光标自定义为文本,android,filter,cursor,autocompletetextview,Android,Filter,Cursor,Autocompletetextview,我通过扩展AutoCompleteTextView(使用名为setCursorAdapter的专用函数)创建了一个自定义视图。我提供了一个SimpleCorsorAdapter并添加了一个FilterQueryProvider。我用它来创建一个数字列表,在这个列表中,我需要能够在数字中的任何位置搜索匹配项 public void setCursorAdapter(final Uri uri, final String key) { Cursor c = getContext()

我通过扩展AutoCompleteTextView(使用名为setCursorAdapter的专用函数)创建了一个自定义视图。我提供了一个SimpleCorsorAdapter并添加了一个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@...

如何避免这种情况并正确显示(数字)文本


谢谢

解决了:SimpleCursorAdapter.converToString(游标)——我重写了这个函数以提取值

谢谢

更好的方法是使用