編輯:關於Android編程
本文實例講述了Android AutoCompleteTextView控件基本用法。分享給大家供大家參考,具體如下:
當輸入部分內容之後會有相關的建議,類似於百度提示信息
1、在布局文件中聲明一個AutoCompleteTextView
<AutoCompleteTextView
android:id="@+id/autocomplete_country"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
/>
2、定義一個提示條目的樣式,在layout目錄下建立list_item.xml文件
<?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="10dp" android:textSize="16sp" android:textColor="#000"> </TextView>
3、它需要使用ArrayAdapter來提供數據
public void setAutoCompleteTextView(){
autoCompleteTextView = (AutoCompleteTextView)findViewById(R.id.autocomplete_country);
//COUNTRIES是一個數組,AutoCompleteTextView會將數組內容和用戶輸入的匹配,然後再顯示出來提示用戶
//R.layout.list_item顯示的是提示信息顯示的內容的樣式
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, R.layout.list_item, COUNTRIES);
autoCompleteTextView.setAdapter(arrayAdapter);
}
備注:COUNTRIES是一個數組類型
4、將AutoCompleteTextView和ArrayAdapter聯系起來
更多關於Android相關內容感興趣的讀者可查看本站專題:《Android文件操作技巧匯總》、《Android編程開發之SD卡操作方法匯總》、《Android開發入門與進階教程》、《Android資源操作技巧匯總》、《Android視圖View技巧總結》及《Android控件用法總結》
希望本文所述對大家Android程序設計有所幫助。
[深入剖析React Native]React 初探
認識ReactReact是一個用於構建用戶界面的JavaScript庫。 React主要用於構建UI,很多人認為React是MVC中的V,即視圖。 React起源於Fac
Android開發:AsyncTask源代碼完全解析
從事Java開發以來,接觸過很多的開源代碼,自己能夠明白代碼但是想要表達出來卻有點困難,從今天開始,逐漸開始對一些開源代碼進行解析並記錄成blog分享出來,希望以此提升自
Android Studio 生成簽名的APK
打開項目以後,點擊項目,選擇 Build 菜單, 然後選擇 Generate Signed APK. 如下圖所示:打開生成對話框:選擇 Create new... 按鈕,
Android實現屏幕鎖定源碼詳解
最近有朋友問屏幕鎖定的問題,自己也在學習,網上找了下也沒太詳細的例子,看的資料書上也沒有有關屏幕鎖定程序的介紹,下個小決心,自己照著官方文檔學習下,現在做好了,廢話不多說