AutoCompleteTextView doesn't show dictionary suggestions

匆匆过客 提交于 2019-12-12 13:14:35

问题


I have a custom AutoCompleteTextView where the user can enter text and whenever the user writes @ I show a dropdown with suggestions of custom usernames. Unfortunately, I also need to show the dictionary word suggestions above the keyboard and, for some reason, AutoCompleteTextView doesn't show dictionary suggestions, although it inherits from EditText where it does show.

So, does anyone know what the problem is and how to fix it? Or should I go to a different route to obtain what I want.


回答1:


I ran into the same problem. The AutoCompleteTextView constructor sets the InputType flag EditorInfo.TYPE_TEXT_FLAG_AUTO_COMPLETE. I confirmed that this flag inhibits the normal text suggestions. The code reads:

    // 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);
    }

Despite this comment, I've had preliminary success with removing the flag, as in:

AutoCompleteTextView t = (AutoCompleteTextView)v.findViewById(id);
t.setInputType( t.getInputType() & (~EditorInfo.TYPE_TEXT_FLAG_AUTO_COMPLETE) );



回答2:


I had the same issue, I recommend extend AutocompleteTextView class and add this line in each constructor:

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


来源:https://stackoverflow.com/questions/9466786/autocompletetextview-doesnt-show-dictionary-suggestions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!