AutoCompleteTextView
1.功能動态比對輸入的内容,如百度搜尋引擎當輸入文本時,可以根據内容顯示比對的熱門資訊
2.屬性:android:completionThresh=“2”//設定輸入多少字元時比對
AutoCompleteTextView:
擴充卡應用:擴充卡的意思就是用資料源去比對已有的資料。
第一步:初始化控件private AutoCompleteTextView acTextView;
第二步:需要一個擴充卡ArrayAdapter adapter=new ArrayAdapter,(this,android.R.layout.simple_list>item>1,objects);其中this(context)代表上下文對象,布局檔案(resource)為系統設定好的,類似于main.xml檔案,資料源(objects)。
第三步:初始化資料源---這資料源去比對文本框輸入的内容 使用數組
第四步:将adpter 與目前AutoCompletetTextView綁定 acTextView.setAdapter(adapter);
在main.xml布局檔案中加上android:completionthreshold="3"設定輸入多少個字元才彈出比對項
MultiAutoCompleteTextView
以特定符号分割 多次自動比對
private String[] res = {"beijing1","beijing2","shanghai1","shanghai2","guangzhou","shenzhen"};//定義資料源
//初始化變量
private MultiAutoCompleteTextView macTestView;
macTestView = (MultiAutoCompleteTextView) findViewById(R.id.multiAutoCompleteTextView1);
//建立擴充卡
ArrayAdapter adapter = new ArrayAdapter(this,
android.R.layout.simple_list_item_1, res);
macTestView.setAdapter(adapter);
macTestView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());//以逗号分隔