android控件学习之六 AutoCompleteTextView

2025-07-20 09:26:45

1、首先建立一个项目,名称为AutoCompleteTest,参数配置如下,建好项目

android控件学习之六 AutoCompleteTextView
android控件学习之六 AutoCompleteTextView

2、在main.xml中声明AutoCompleteTextView属性,其中android:completionThreshold定义了从第几个字符开始显示候补列表,我们设置为1

android控件学习之六 AutoCompleteTextView

3、AutoCompleteTest 方法实现,主要是构造好字符串数组,作为提示的文本信息,将字符串数组添加到数组适配器中,找到AutoCompleteTextView控件对象,将适配器进行赋值,就完成了简单的自动查询框了

android控件学习之六 AutoCompleteTextView
android控件学习之六 AutoCompleteTextView

4、看程序运行效果图:

android控件学习之六 AutoCompleteTextView
android控件学习之六 AutoCompleteTextView
android控件学习之六 AutoCompleteTextView

5、同时有一个MultiAutoCompleteTextView,也可以完成自动查询功能,不过用户必须提供一个MultiAutoCo罪焐芡拂mpleteTextView.Tokenizer用来区分不同的子串。他默认是输入两个字符开始查询,那么我们也进行相应的初始化

android控件学习之六 AutoCompleteTextView
android控件学习之六 AutoCompleteTextView
android控件学习之六 AutoCompleteTextView
android控件学习之六 AutoCompleteTextView
声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
猜你喜欢