立即在 Android 上显示自动完成功能
Android 自动完成功能仅在两个字母后启动。如何才能在刚刚选择字段时显示列表?
The Android autocomplete only starts after two letters. How can I make it so the list appears when the field is just selected?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
要使自动完成功能在焦点上显示,请添加焦点侦听器并在字段获得焦点时显示下拉列表,如下所示:
或者如果不需要焦点部分,则只需调用 editText.showDropDown() 。
To get the autocomplete to show on focus add focus listener and show the drop down when the field gets focus, like this:
Or just call editText.showDropDown() if you don't need the focus part.
查看 setThreshold 方法:
Have a look to setThreshold method:
扩展 AutoCompleteTextView,重写 fullToFilter() 方法和阈值方法,以便它不会用 1 阈值替换 0 阈值:
Extend the AutoCompleteTextView, overriding the enoughToFilter() methods and the threshold methods so that it doesn't replace the 0 threshold with a 1 threshold:
对于想要使用 SearchView 更改阈值的人,您必须使用:
For people who want to change threshold using SearchView you have to use:
根据阈值设置,在适配器左侧填充一个/两个白色字符。
Pad your adapter with one/two white character on left depending on the threshold setting.
更改 XML 中设置的替代方法:
正如其他人提到的,您需要设置“自动完成阈值' 到 1
除了 @systempuntoout 提到的以外。
您也可以在 XML 文件中执行此操作,如图所示,
请注意以下行:android:completionThreshold="1"
Alternate method of changing the setting in your XML:
As mentioned by others you need to set your 'Auto Completion Threshold' to 1
Other than what @systempuntoout mentioned.
You can also do that in your XML file as shown
Note the line : android:completionThreshold="1"