Android AutoCompleteTextView控件基本用法示例
本文實例講述了Android AutoCompleteTextView控件基本用法。分享給大家供大家參考,具體如下:
當輸入部分內(nèi)容之后會有相關(guān)的建議,類似于百度提示信息
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來提供數(shù)據(jù)
public void setAutoCompleteTextView(){
autoCompleteTextView = (AutoCompleteTextView)findViewById(R.id.autocomplete_country);
//COUNTRIES是一個數(shù)組,AutoCompleteTextView會將數(shù)組內(nèi)容和用戶輸入的匹配,然后再顯示出來提示用戶
//R.layout.list_item顯示的是提示信息顯示的內(nèi)容的樣式
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, R.layout.list_item, COUNTRIES);
autoCompleteTextView.setAdapter(arrayAdapter);
}
備注:COUNTRIES是一個數(shù)組類型
4、將AutoCompleteTextView和ArrayAdapter聯(lián)系起來
更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android文件操作技巧匯總》、《Android編程開發(fā)之SD卡操作方法匯總》、《Android開發(fā)入門與進階教程》、《Android資源操作技巧匯總》、《Android視圖View技巧總結(jié)》及《Android控件用法總結(jié)》
希望本文所述對大家Android程序設計有所幫助。
- Android高級組件AutoCompleteTextView自動完成文本框使用詳解
- Android中EditText和AutoCompleteTextView設置文字選中顏色方法
- Android AutoCompleteTextView控件使用實例
- 基于Android中的 AutoCompleteTextView實現(xiàn)自動填充
- 實例講解Android中的AutoCompleteTextView自動補全組件
- Android AutoCompleteTextView連接數(shù)據(jù)庫自動提示的方法(附demo源碼下載)
- Android仿百度谷歌搜索自動提示框AutoCompleteTextView簡單應用示例
- Android自動編輯文本框(AutoCompleteTextView)使用方法詳解
- Android中AutoCompleteTextView自動提示
- android中AutoCompleteTextView的簡單用法(實現(xiàn)搜索歷史)
- Android開發(fā)高級組件之自動完成文本框(AutoCompleteTextView)用法示例【附源碼下載】
相關(guān)文章
android教程之intent的action屬性使用示例(intent發(fā)短信)
這篇文章主要介紹了android中intent的action屬性使用示例,提供了使用intent撥打電話、發(fā)送短信、播放mp3的代碼2014-01-01
android中寫一個內(nèi)部類來選擇文件夾中指定的圖片類型實例說明
選擇文件夾中指定的圖片類型,本類是用來選擇文件夾中是.jpg類型的圖片具體實現(xiàn)如下,感興趣的朋友可以參考下哈2013-06-06
Android開發(fā)數(shù)據(jù)結(jié)構(gòu)算法ArrayList源碼詳解
這篇文章主要為大家介紹了Android開發(fā)數(shù)據(jù)結(jié)構(gòu)算法ArrayList源碼詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-10-10
詳解Android中OkHttp3的例子和在子線程更新UI線程的方法
本篇文章主要介紹了詳解Android中OkHttp3的例子和在子線程更新UI線程的方法 ,非常具有實用價值,需要的朋友可以參考下2017-05-05
Android用Scroller實現(xiàn)一個可向上滑動的底部導航欄
本篇文章主要介紹了Android用Scroller實現(xiàn)一個可上滑的底部導航欄,具有一定的參考價值,有興趣的小伙伴們可以參考一下2017-07-07
Android SDK Manager國內(nèi)無法更新的解決方案
本文主要介紹Android SDK Manager國內(nèi)無法更新的解決方案,這里提供了解決方法,及簡單說明實現(xiàn)流程,有興趣的小伙伴可以參考下2016-09-09

