Android用戶輸入自動提示控件AutoCompleteTextView使用方法
一、簡介
1、AutoCompleteTextView的作用
2、AutoCompleteTextView的類結構圖
也就是擁有EditText的各種功能
3、AutoCompleteTextView工作原理
AutoCompleteTextView的自動提示功能肯定需要適配器提供數據
4、Android里的適配器
5、適合AutoCompleteTextView的適配器
ArrayAdapter
二、AutoCompleteTextView實現自動提示的方法
1)AutoCompleteTextView實現自動提示的方法
第一步、創(chuàng)建適配器
String[] arr={"凱撒","凱撒廣場","凱撒大帝"};
ArrayAdapter<String> adapter= new ArrayAdapter<String>(this, R.layout.textview, arr);
第二步、AutoCompleteTextView對象應用適配器
autoCompleteTextView1.setAdapter(adapter);
說明:
提示文本是用textview實現的,提示文本里面的提示數據就是String[] arr。
三、代碼實例
代碼:
fry.Activity01
package fry; import com.example.AutoCompleteTextViewDemo1.R; import android.app.Activity; import android.os.Bundle; import android.widget.ArrayAdapter; import android.widget.AutoCompleteTextView; public class Activity01 extends Activity{ private AutoCompleteTextView autoCompleteTextView1; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.activity01); autoCompleteTextView1=(AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1); /* * AutoCompleteTextView實現自動提示的方法 * 第一步、創(chuàng)建適配器 * 第二步、AutoCompleteTextView對象應用適配器 * */ String[] arr={"凱撒","凱撒廣場","凱撒大帝"}; ArrayAdapter<String> adapter= new ArrayAdapter<String>(this, R.layout.textview, arr); autoCompleteTextView1.setAdapter(adapter); } }
fry.Activity01
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <AutoCompleteTextView android:id="@+id/autoCompleteTextView1" android:layout_width="match_parent" android:layout_height="wrap_content" /> </LinearLayout>
/AutoCompleteTextViewDemo1/res/layout/textview.xml
<?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <!-- 這里是直接TextView,而不是layout下的TextView --> </TextView >
四、易錯點
1、這里是直接TextView,而不是layout下的TextView
/AutoCompleteTextViewDemo1/res/layout/textview.xml
<?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <!-- 這里是直接TextView,而不是layout下的TextView --> </TextView >
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
- Android自動獲取輸入短信驗證碼庫AutoVerifyCode詳解
- Android AutoWrapTextView中英文排版問題的解決方法
- Android中使用 AutoCompleteTextView 實現手機號格式化附帶清空歷史的操作
- Android自動編輯文本框(AutoCompleteTextView)使用方法詳解
- Android中AutoCompleteTextView自動提示
- Android仿新浪微博oauth2.0授權界面實現代碼(2)
- android中AutoCompleteTextView的簡單用法(實現搜索歷史)
- Android仿百度谷歌搜索自動提示框AutoCompleteTextView簡單應用示例
- 關于Android HTML5 audio autoplay無效問題的解決方案
- Android AutoCompleteTextView自動提示文本框實例代碼
- Android App開發(fā)的自動化測試框架UI Automator使用教程
- Android中AutoCompleteTextView與TextWatcher結合小實例
- Android AutoValue使用和擴展庫
相關文章
Android中SharedPreferences簡單使用實例
這篇文章主要介紹了Android中SharedPreferences簡單使用案例,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-10-10Android 自定義SeekBar動態(tài)改變硬件音量大小實現和音量鍵的同步(推薦)
這篇文章主要介紹了 Android 自定義SeekBar動態(tài)改變硬件音量大小實現和音量鍵的同步效果,整段代碼簡單易懂,非常不錯,具有參考借鑒價值,需要的朋友可以參考下2017-01-01