我正在使用具有自定义布局的AutoCompleteTextView适配器。问题是我不知道如何一次只限制一个结果,就像在默认布局中一样。
我读到有可能限制高度,但并非在所有屏幕上都起作用。感谢您的关注。

我在我的activity_main布局上放了这个。

<AutoCompleteTextView android:id="@+id/autotext"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:minWidth="480dp"
android:layout_weight="1"
android:maxLength="23"
android:maxLines="1"
android:textColor="#000000" />


这是适配器的布局。

<TextView android:id="@+id/textpop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:textSize="17sp"/>

最佳答案

看看this code。基本上,它是SDK ArrayAdapter类的代码,只做了少量修改(不计入)。如果您只想在AutoCompleteTextView中显示一个建议,则可以对链接中的类进行小的修改,如下所示:performFiltering()方法:

// ... the rest of that method
if (newValues.size() > 1) { // if we have more than an item in the list
    // get the first suggestion
    T oneItem = newValues.get(0);
    // empty the suggestion list
    newValues.clear();
    // add the only suggestion.
    newValues.add(oneItem);
}
results.values = newValues;
results.count = newValues.size();

10-07 19:41
查看更多