- AutoCompleteTextView继承EditText,默认为输入2个字符才出现提示
- MutiAutoCompleteTextView继承AutoCompleteTextView,使用setTokenizer设置分词方式(CommaTokenizer)
- 设置","逗号为分隔符:
setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer())
资源文件
- who
- where
- what
- how
- foot
- city
- cupcake
- mashmallow
- nougat
布局文件
两个自动补全输入框效果图
AutoTextView输入框效果图
MutiAutoTextView输入框效果图
实现java代码
String hints[]=getResources().getStringArray(R.array.hints);
AutoCompleteTextView autoCompleteTextView= (AutoCompleteTextView) findViewById(R.id.autoTextView);
MultiAutoCompleteTextView multiAutoCompleteTextView= (MultiAutoCompleteTextView) findViewById(R.id.multiTextView);
ArrayAdapter adapter=new ArrayAdapter(this,android.R.layout.simple_list_item_1,hints);
autoCompleteTextView.setAdapter(adapter);
multiAutoCompleteTextView.setAdapter(adapter);
//设置","逗号去分割
multiAutoCompleteTextView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());