AutoCompleteTextView不显示字典建议

3
我有一个定制的AutoCompleteTextView,用户可以输入文本,每当用户写@符号时,我会显示一个下拉列表,列出自定义用户名的建议。不幸的是,我还需要在键盘上方显示字典单词建议,但由于某种原因,AutoCompleteTextView并不显示字典建议,尽管它继承自EditText,后者就能够显示字典建议。所以,请问有人知道问题所在并知道如何解决吗?或者我应该换一种方法来达到我的目的。
2个回答

1
我遇到了同样的问题。 AutoCompleteTextView 构造函数设置了 InputType 标志 EditorInfo.TYPE_TEXT_FLAG_AUTO_COMPLETE。 我确认这个标志会抑制正常的文本建议。 代码如下:
    // Always turn on the auto complete input type flag, since it
    // makes no sense to use this widget without it.
    int inputType = getInputType();
    if ((inputType&EditorInfo.TYPE_MASK_CLASS)
            == EditorInfo.TYPE_CLASS_TEXT) {
        inputType |= EditorInfo.TYPE_TEXT_FLAG_AUTO_COMPLETE;
        setRawInputType(inputType);
    }

尽管有这样的评论,但我已经初步成功地删除了标记,如下所示:
AutoCompleteTextView t = (AutoCompleteTextView)v.findViewById(id);
t.setInputType( t.getInputType() & (~EditorInfo.TYPE_TEXT_FLAG_AUTO_COMPLETE) );

0

我曾经遇到过同样的问题,我建议扩展AutocompleteTextView类并在每个构造函数中添加这行代码:

setInputType(getInputType() & (~EditorInfo.TYPE_TEXT_FLAG_AUTO_COMPLETE));

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接