AutoCompleteTextView
AutoCompleteTextView控件的功能是自动展示与输入的文本相匹配的列表
属性
- completionThreshold: 指定输入字符在到几位之后展示匹配列表,
用法
// 定义原始数据
String [] res = {"beijing1","beijing2","beijing3","shanghai1","shanghai2"};
// 找到该控件
AutoCompleteTextView autoCompleteTextView = findViewById(R.id.autoCompleteTextView);
// 定义ArrayAdapter
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,R.layout.support_simple_spinner_dropdown_item,res);
// AutoCompleteTextView绑定adapter
autoCompleteTextView.setAdapter(adapter);
示例
image.png
MultiAutoCompleteTextView
MultiAutoCompleteTextView控件的功能是自动展示与输入的文本相匹配的列表,支持多选
用法
// 定义原始数据
String [] res = {"beijing1","beijing2","beijing3","shanghai1","shanghai2"};
MultiAutoCompleteTextView macTextView = findViewById(R.id.multiAutoCompleteTextView);
macTextView.setAdapter(adapter);
macTextView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer()); //设置分隔符
示例
image.png
网友评论