public class MainActivity extends Activity {
private AutoCompleteTextView auto_in;
private MultiAutoCompleteTextView multi_auto;
private static final String[] autoStr = {
"ab", "abc", "abcd", "abcde", "abcdef"
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
auto_in = (AutoCompleteTextView)findViewById(R.id.auto_in);
multi_auto = (MultiAutoCompleteTextView) findViewById(R.id.multi_auto);
ArrayAdapter adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line, autoStr);
/**
* Specifies the minimum number of characters the user has to type in the edit box
* before the drop down list is shown.
* When threshold is less than or equals 0, a threshold of 1 is applied.
*/
auto_in.setThreshold(3);
auto_in.setAdapter(adapter);
/**
* MultiAutoCompleteTextView繼承於AutoCompleteTextView,可以在輸入框中一直增加新的選取值
* 在進行setAdapter之後還需要調用setTokenizer(),否則會出現錯誤
*/
multi_auto.setAdapter(adapter);
/**
* This simple Tokenizer can be used for lists
* where the items are separated by a comma and one or more spaces
*/
multi_auto.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
}
}
android自動提示
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.