</MultiAutoCompleteTextView>
//android:completionThreshold="3"为输入第几个字符以后开始补全
//android:ems="10"显示的最多的字符的个数
public class MainActivity extends Activity {
private AutoCompleteTextView actv;
private MultiAutoCompleteTextView mactv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/**
* 1初始化一个控件
* 2定义一个适配器
* 3定义一个数组....作为数据源
* 将adapter与当前控件绑定
*/
String[] s={"beijing1","beijing2","beijing3","shanghai"};
actv=(AutoCompleteTextView) findViewById(R.id.actv);
ArrayAdapter<String> adapter=new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, s);
actv.setAdapter(adapter);
/**
* 1初始化一个控件
* 2定义一个适配器
* 3定义一个数组。。。。作为数据源
* 4将adapter与当前控件绑定
* 5设置分隔符
*/
mactv=(MultiAutoCompleteTextView) findViewById(R.id.multiAutoCompleteTextView1);
mactv.setAdapter(adapter);
mactv.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}