public class MainActivity extends ActionBarActivity {
// 自动匹配输入框AutoCompleteTextView
private AutoCompleteTextView acTextView;
// 自动匹配输入框(匹配多个)MultiAutoCompleteTextView
private MultiAutoCompleteTextView macTextView;
// 准备数据源
private String[] res = { "test1", "test2", "textview1", "textview2" };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// 找到AutoCompleteTextView
acTextView = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1);
// 绑定数据源
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, res);
acTextView.setAdapter(adapter);
// 找到MultiAutoCompleteTextView
macTextView = (MultiAutoCompleteTextView) findViewById(R.id.multiAutoCompleteTextView1);
macTextView.setAdapter(adapter);
// 设置逗号分隔符
macTextView
.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
}
// 自动匹配输入框AutoCompleteTextView
private AutoCompleteTextView acTextView;
// 自动匹配输入框(匹配多个)MultiAutoCompleteTextView
private MultiAutoCompleteTextView macTextView;
// 准备数据源
private String[] res = { "test1", "test2", "textview1", "textview2" };
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// 找到AutoCompleteTextView
acTextView = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1);
// 绑定数据源
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, res);
acTextView.setAdapter(adapter);
// 找到MultiAutoCompleteTextView
macTextView = (MultiAutoCompleteTextView) findViewById(R.id.multiAutoCompleteTextView1);
macTextView.setAdapter(adapter);
// 设置逗号分隔符
macTextView
.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
}
}