安卓:AutoCompleteTextView使用默认的建议 [英] Android: AutoCompleteTextView with default suggestions
问题描述
我如何向用户显示之前的一些默认建议AutoCompleteTextView键入什么?我无法找到一个方法来做到这一点,即使与创建扩展AutoCompleteTextView自定义类。
How do I show some default suggestions for AutoCompleteTextView before the user type anything? I cannot find a way to do this even with creating a custom class that extends AutoCompleteTextView.
我想,以示对常见的输入值,建议保存从打字的用户。
I want to show suggestions for common input values to save the user from typing.
有什么建议?
推荐答案
您应该继承 AutoCompleteTextView
并覆盖 enoughToFilter()
返回真
所有的时间。之后,你可以调用 performFiltering(,0)
(这是一个受保护的功能,这样你就可以通过在你的类中的公共函数导出该调用)。
You should subclass AutoCompleteTextView
and override enoughToFilter()
to return true
all the time. After that you can call performFiltering("",0)
(it's a protected function, so you can export this call via a public function in your class).
这样的东西:
public class ContactsAutoCompleteTextView extends AutoCompleteTextView {
public ContactsAutoCompleteTextView(Context context) {
super(context);
}
public ContactsAutoCompleteTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ContactsAutoCompleteTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public boolean enoughToFilter() {
return true;
}
public void temp() {
performFiltering("",0);
}
}
这篇关于安卓:AutoCompleteTextView使用默认的建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!