MultiAutoCompleteTextView未显示键盘建议

时间:2014-12-29 16:04:38

标签: android android-layout multiautocompletetextview

我在我的应用中使用MultiAutoCompleteTextView。它是Android API中令人敬畏的控件。但是我面临一些问题。一个,最烦人的是,在我的Nexus 5上,它没有显示键盘建议。在Xperia Z上,显示了键盘建议。无法找到原因。任何人都可以帮助/指导我吗?这是我MultiAutoCompleteTextView

的XML
<MultiAutoCompleteTextView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:hint="Post a question, idea or update"
    android:gravity="top"
    android:textColorHint="#9e9e9e"
    android:textColor="#000000"
    android:textSize="15sp"
    android:padding="10dp"
    android:background="@null" />

1 个答案:

答案 0 :(得分:2)

我查看了源代码,并在AutoCompleteTextView

中找到了此代码
    // 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);
    }

InputType的javaDoc页面中,TYPE_TEXT_FLAG_AUTO_COMPLETE定义为。

  

TYPE_CLASS_TEXT的标志:文本编辑器(表示应用程序)正在根据自己的语义执行输入文本的自动完成,它将在用户键入时显示。

这意味着您有自己的完成语义,这意味着键盘禁用其建议是合乎逻辑的。

我认为当您使用setInputType()方法以编程方式更改inputType时,可以禁用此行为并获取键盘建议。

你可以试试这个:

mAutoCompletetextView.setInputType(EditText.TYPE_CLASS_TEXT | EditText.TYPE_TEXT_FLAG_AUTO_CORRECT);
相关问题