我正在使用 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();
关于android - 将 AutoCompleteTextView 限制为仅一个结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13688904/