使用AutoCompleteTextView控件的步驟
作者:佚名
AutoCompleteTextView的功能類似于百度或者Google在搜索欄輸入信息的時(shí)候,彈出的與輸入信息接近的提示信息。
AutoCompleteTextView的功能類似于百度或者Google在搜索欄輸入信息的時(shí)候,彈出的與輸入信息接近的提示信息。具體效果是,一個(gè)可編輯的文本視圖,當(dāng)用戶輸入信息后彈出提示。提示列表顯示在一個(gè)下拉菜單中,用戶可以從中選擇一項(xiàng),以完成輸入。提示列表是從一個(gè)數(shù)據(jù)適配器獲取的數(shù)據(jù)。
以下是使用的步驟:
第一步:在布局文件中定義控件
- <AutoCompleteTextView
- android:id="@+id/actv"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
- />
第二步:在Activity中引用
- AutoCompleteTextView actv = (AutoCompleteTextView) findViewById(R.id.actv);
第三步:創(chuàng)建一個(gè)適配器來保存數(shù)據(jù)
- ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
- ndroid.R.layout.simple_dropdown_item_1line,new String[] {"English", "Hebrew", "Hindi", "German" });
第四步:將適配器與AutoCompleteTextView相關(guān)聯(lián)
- actv.setAdapter(adapter);
責(zé)任編輯:徐川
來源:
OSChina