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