【问题标题】:AutoCompleteTextView with SimpleCursorAdapter for Contacts not returning cursor actual value用于联系人的具有 SimpleCursorAdapter 的 AutoCompleteTextView 不返回光标实际值
【发布时间】:2016-10-02 18:42:19
【问题描述】:

我有一个 AutoCompleteTextView,它使用 SimpleCursorAdapter 过滤输入字段的电子邮件。虽然有一些 deprecated 命令我不知道如何返工,但我已经成功了。

我遇到的唯一问题是,当我从提供的列表中选择一个值时,我没有选择电子邮件地址,而是如下所示:

android.content.ContentResolver$CursorWrapperInner@13a08d9c

这是我的代码:

final AutoCompleteTextView edt_Contact = (AutoCompleteTextView)findViewById(idTo);

    ContentResolver cr = getContentResolver();
    String[] projection={ContactsContract.CommonDataKinds.Email._ID,ContactsContract.CommonDataKinds.Email.ADDRESS};
    Cursor cursor = cr.query(ContactsContract.CommonDataKinds.Email.CONTENT_URI, projection, null, null, null);

    startManagingCursor(cursor);
    String[] from = new String[] { ContactsContract.CommonDataKinds.Email.ADDRESS};
    int[] to = new int[] { android.R.id.text1};
    SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_1, cursor, from, to);

    adapter.setFilterQueryProvider(new FilterQueryProvider() {
        public Cursor runQuery(CharSequence constraint) {
            return getContentResolver().query(ContactsContract.CommonDataKinds.Email.CONTENT_URI,
                    new String[] {},
                    ContactsContract.CommonDataKinds.Email.ADDRESS + " LIKE '%" + constraint + "%'",
                    null, null);
        }
    });

    edt_Contact.setAdapter(adapter);

关于如何获取实际选定值以在选择时填充 AutoCompleteTextView 的任何建议?

此外,如前所述,已弃用的项目是 startManagingCursorSimpleCursorAdapter

【问题讨论】:

    标签: android android-contacts autocompletetextview simplecursoradapter


    【解决方案1】:

    找到了解决方案,我在这里发布给其他有类似情况的人

    我需要添加以下内容

    adapter.setStringConversion(1);
    

    我在上面示例的最后一行之前添加了它。这改变了

    的结果

    android.content.ContentResolver$CursorWrapperInner@13a08d9c

    到选定的电子邮件地址。

    对于任何使用MultiAutoCompleteTextView 来做同样事情的人来说,这也是一个提醒,这段代码也适用于此...只需在AutoCompleteTextView 之前更改添加 Multi 并添加您选择的.setTokenizer

    【讨论】:

      猜你喜欢
      • 2014-03-13
      • 2020-09-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-18
      • 1970-01-01
      相关资源
      最近更新 更多