在android中我们可以使用AutoCompleteTextView来实现自动提示功能。
我们将需要进行提示的数据放入AdapterArray中,然后用AutoCompleteTextView的setAdapter方法,就可以让AutoCompleteTextView具有自动完成提示的功能了.
MultiAutoCompleteTextView也是具有自动完成提示的功能,它和AutoCompleteTextView的区别就是 MultiAutoCompleteTextView可以在输入框中一直增加新的选取值。编写方式也有所不同,在进行setAdapter之后还需要调用setTokenizer(),否则会出现错误
我们将需要进行提示的数据放入AdapterArray中,然后用AutoCompleteTextView的setAdapter方法,就可以让AutoCompleteTextView具有自动完成提示的功能了.
- private static final String[] autoStr = { "a", "abc", "abcd", "abcde" };
- ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_dropdown_item_1line, autoStr);
- AutoCompleteTextView myAutoCompleteTextView = (AutoCompleteTextView)findViewById(R.id.myAutoCompleteTextView);
- myAutoCompleteTextView.setAdapter(adapter);
MultiAutoCompleteTextView也是具有自动完成提示的功能,它和AutoCompleteTextView的区别就是 MultiAutoCompleteTextView可以在输入框中一直增加新的选取值。编写方式也有所不同,在进行setAdapter之后还需要调用setTokenizer(),否则会出现错误
- MultiAutoCompleteTextView autoCompleteTextView = (MultiAutoCompleteTextView) findViewById(R.id.myAutoCompleteTextView);
- autoCompleteTextView.setAdapter(adapter);
- autoCompleteTextView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());