Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AutoCompleteTextView doesn't show dictionary suggestions

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.

like image 984
Catalin Morosan Avatar asked Jan 26 '26 13:01

Catalin Morosan


1 Answers

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) );
like image 75
Marius Bjørnstad Avatar answered Jan 28 '26 06:01

Marius Bjørnstad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!