Android用戶輸入自動提示控件AutoCompleteTextView使用方法
一、簡介
1、AutoCompleteTextView的作用

2、AutoCompleteTextView的類結(jié)構(gòu)圖

也就是擁有EditText的各種功能
3、AutoCompleteTextView工作原理
AutoCompleteTextView的自動提示功能肯定需要適配器提供數(shù)據(jù)

4、Android里的適配器

5、適合AutoCompleteTextView的適配器
ArrayAdapter
二、AutoCompleteTextView實現(xiàn)自動提示的方法
1)AutoCompleteTextView實現(xiàn)自動提示的方法
第一步、創(chuàng)建適配器
String[] arr={"凱撒","凱撒廣場","凱撒大帝"};
ArrayAdapter<String> adapter= new ArrayAdapter<String>(this, R.layout.textview, arr);
第二步、AutoCompleteTextView對象應用適配器
autoCompleteTextView1.setAdapter(adapter);
說明:
提示文本是用textview實現(xiàn)的,提示文本里面的提示數(shù)據(jù)就是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實現(xiàn)自動提示的方法
* 第一步、創(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 >
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
- Android自動獲取輸入短信驗證碼庫AutoVerifyCode詳解
- Android AutoWrapTextView中英文排版問題的解決方法
- Android中使用 AutoCompleteTextView 實現(xiàn)手機號格式化附帶清空歷史的操作
- Android自動編輯文本框(AutoCompleteTextView)使用方法詳解
- Android中AutoCompleteTextView自動提示
- Android仿新浪微博oauth2.0授權(quán)界面實現(xiàn)代碼(2)
- android中AutoCompleteTextView的簡單用法(實現(xiàn)搜索歷史)
- Android仿百度谷歌搜索自動提示框AutoCompleteTextView簡單應用示例
- 關(guān)于Android HTML5 audio autoplay無效問題的解決方案
- Android AutoCompleteTextView自動提示文本框?qū)嵗a
- Android App開發(fā)的自動化測試框架UI Automator使用教程
- Android中AutoCompleteTextView與TextWatcher結(jié)合小實例
- Android AutoValue使用和擴展庫
相關(guān)文章
Android 將網(wǎng)絡的Url資源轉(zhuǎn)換為Drawable資源方式
這篇文章主要介紹了Android 將網(wǎng)絡的Url資源轉(zhuǎn)換為Drawable資源方式,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-03-03
Flutter底部不規(guī)則導航的實現(xiàn)過程
這篇文章主要給大家介紹了關(guān)于Flutter底部不規(guī)則導航的實現(xiàn)過程,文中通過示例代碼介紹的非常詳細,對大家學習或者使用Flutter具有一定的參考學習價值,需要的朋友們下面來一起學習學習吧2019-08-08
android動態(tài)布局之動態(tài)加入TextView和ListView的方法
這篇文章主要介紹了android動態(tài)布局之動態(tài)加入TextView和ListView的方法,涉及Android動態(tài)布局的實現(xiàn)技巧,需要的朋友可以參考下2015-05-05
Android實現(xiàn)底部狀態(tài)欄切換的兩種方式
這篇文章主要介紹了Android實現(xiàn)底部狀態(tài)欄切換功能,在文中給大家提到了兩種實現(xiàn)方式,本文分步驟給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下2019-06-06
Android開發(fā)基礎之創(chuàng)建啟動界面Splash Screen的方法
這篇文章主要介紹了Android開發(fā)基礎之創(chuàng)建啟動界面Splash Screen的方法,以實例形式較為詳細的分析了Android定制啟動界面的布局及功能實現(xiàn)相關(guān)技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-10-10
Android仿QQ微信未讀消息小紅點BadgeHelper
這篇文章主要介紹了Android仿QQ微信未讀消息小紅點的實現(xiàn),本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-09-09

