AutoCompleteTextView:
An editable text view that shows completion suggestions automatically while the user is typing. The list of suggestions is displayed in a drop down menu from which the user can choose an item to replace the content of the edit box with.
The drop down can be dismissed at any time by pressing the back key or, if no item is selected in the drop down, by pressing the enter/dpad center key.
The list of suggestions is obtained from a data adapter and appears only after a given number of characters defined by the threshold.
即,一个可输入的TextView,但是,它绑定了一些初始的数据,当用户输入一部分字符(默认是2个字符)后,它会根据绑定的内容而自动匹配,并把符合的结果以下拉菜单的形式显示出来,用户可以单击某个下拉菜单中的选项而完成输入。
重要属性:
android:completionThreshold="1",Defines the number of characters that the user must type before completion suggestions are displayed in a drop down menu。即,设置用户输入多少个字符后,才匹配,并出现下拉框。
示例1:
autocomplete_1.xml
AutoComplete1.java
示例2:
autocomplete_4.xml
AutoComplete4.java
本文通过两个示例介绍了如何在Android中使用AutoCompleteTextView实现自动补全功能,包括设置属性、初始化数据适配器以及展示下拉菜单以辅助用户输入。示例1展示了基本的AutoCompleteTextView用法,而示例2则利用ContentResolver查询联系人数据,动态生成补全选项。
908

被折叠的 条评论
为什么被折叠?



