MultiAutoCompleteTextView多文本选取
2017-11-15 本文已影响130人
Luyc_Han
布局:
<MultiAutoCompleteTextView
android:id="@+id/multiAutoCompleteTextView1"
android:layout_width="286dp"
android:layout_height="wrap_content"
android:layout_marginStart="60dp"
android:layout_marginTop="48dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/searchid"
android:hint="请选择您要搜索的内容"/>
实现:
/// 获取multiAutoCompleteTextView对象
MultiAutoCompleteTextView multiView = (MultiAutoCompleteTextView)findViewById(R.id.multiAutoCompleteTextView1);
/// 设置数据源数组
String[] temps = {"beijing1","beijing1","beijing1","beijing1","beijing1"};
/// 设置一个适配器
ArrayAdapter<String> tempAdater = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, temps);
/// 将适配器与当前MultiAutoCompleteTextView控件绑定
multiView.setAdapter(tempAdater);
/// 设置以逗号为分隔为结束的符号
multiView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());