AutoCompleteTextview
动态匹配输入内容文本框
属性:
android:completionThreshold="2"; 设置输入多少字符时自动匹配
public class MainActivity extends ActionBarActivity {
private AutoCompleteTextView actextview ;
//初始化数据源 去匹配文本框中输入的内容
private String[] res ={"北京" ,"北京1" ,"北京2" ,"上海" ,"上海1" ,"上海2" };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout. activity_main);
//初始化控件
actextview=(AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1 );
//New适配器
ArrayAdapter<String> adapter= new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1 ,res );
//将adpter 与当前AutoCompleteTextView控件绑定
actextview.setAdapter(adapter);
}
}
<AutoCompleteTextView
android:id="@+id/autoCompleteTextView1"
android:layout_width="match_parent"
android:layout_height="50dp"
android:completionThreshold="1"
android:hint="@string/AutoCompleteTextView" >
<requestFocus />
</AutoCompleteTextView >
MultiAutoCompleteTextView
可支持选择多个值(在多次输入的情况下),分别用分隔符分开,并且在每个字选中的时候再次输入值时会自动去匹配。(AutoCompleteTextview 单选)
android:completionThreshold="2"; 设置输入多少字符时自动匹配
mtxt.setTokenizer(new MultiAutoCompleteTextView.CommTokenizer());
maTextView=(MultiAutoCompleteTextView) findViewById(R.id.multiAutoCompleteTextView1 );
maTextView.setAdapter(adapter);
//设置分隔符
maTextView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());