AutoCompleteTextView
1.功能动态匹配输入的内容,如百度搜索引擎当输入文本时,可以根据内容显示匹配的热门信息
2.属性:android:completionThresh=“2”//设置输入多少字符时匹配
AutoCompleteTextView:
适配器应用:适配器的意思就是用数据源去匹配已有的数据。
第一步:初始化控件private AutoCompleteTextView acTextView;
第二步:需要一个适配器ArrayAdapter adapter=new ArrayAdapter,(this,android.R.layout.simple_list>item>1,objects);其中this(context)代表上下文对象,布局文件(resource)为系统设置好的,类似于main.xml文件,数据源(objects)。
第三步:初始化数据源---这数据源去匹配文本框输入的内容 使用数组
第四步:将adpter 与当前AutoCompletetTextView绑定 acTextView.setAdapter(adapter);
在main.xml布局文件中加上android:completionthreshold="3"设置输入多少个字符才弹出匹配项
MultiAutoCompleteTextView
以特定符号分割 多次自动匹配
private String[] res = {"beijing1","beijing2","shanghai1","shanghai2","guangzhou","shenzhen"};//定义数据源
//初始化变量
private MultiAutoCompleteTextView macTestView;
macTestView = (MultiAutoCompleteTextView) findViewById(R.id.multiAutoCompleteTextView1);
//创建适配器
ArrayAdapter adapter = new ArrayAdapter(this,
android.R.layout.simple_list_item_1, res);
macTestView.setAdapter(adapter);
macTestView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());//以逗号分隔