Android 自動(dòng)完成文本框的實(shí)例
Android:自動(dòng)完成文本框
xml文件代碼如下:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <AutoCompleteTextView android:id="@+id/myAutoCompleteTextView" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout>
java文件代碼如下:
package com.example.sample_5_1;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
public class AutoCompleteActivity extends AppCompatActivity {
private static final String[] myStr = new String[]{
"vae","victory","vision","virtue","vital"
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_auto_complete);
ArrayAdapter<String> aa = new ArrayAdapter<String>( //創(chuàng)建適配器
this, // Context
android.R.layout.simple_dropdown_item_1line,
//使用Android自帶的簡(jiǎn)單布局
myStr); //資源數(shù)組
AutoCompleteTextView myAutoCompleteTextView =
(AutoCompleteTextView) findViewById(R.id.myAutoCompleteTextView);
//得到控件的引用
myAutoCompleteTextView.setAdapter(aa); //設(shè)置適配器
myAutoCompleteTextView.setThreshold(1); //定義需要用戶輸入的字符數(shù)
}
}
以上這篇Android 自動(dòng)完成文本框的實(shí)例就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Android開發(fā)手冊(cè)自定義Switch開關(guān)按鈕控件
這篇文章主要為大家介紹了Android開發(fā)手冊(cè)自定義Switch開關(guān)按鈕控件的示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-06-06
Android開發(fā)之TimePicker控件用法實(shí)例詳解
這篇文章主要介紹了Android開發(fā)之TimePicker控件用法,結(jié)合實(shí)例形式詳細(xì)分析了Android項(xiàng)目的建立及TimePicker控件的具體使用技巧,需要的朋友可以參考下2016-02-02
Android Studio 新手入門教程(一)基本設(shè)置圖解
這篇文章主要介紹了Android Studio 新手入門教程(一)基本設(shè)置圖解,需要的朋友可以參考下2017-12-12
Android多設(shè)備多module打包fat-aar(最新推薦)
這篇文章主要介紹了Android多設(shè)備多module打包(fat-aar),本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-03-03
MotionLayout自定義開關(guān)按鈕實(shí)例詳解
這篇文章主要為大家介紹了MotionLayout自定義開關(guān)按鈕實(shí)例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-11-11
Fedora14下android開發(fā): eclipse與ibus確有沖突的問題分析
本篇文章是對(duì)Fedora14下android開發(fā),eclipse與ibus確有沖突的問題進(jìn)行了分析介紹,需要的朋友參考下2013-05-05
Android判斷NavigationBar是否顯示的方法(獲取屏幕真實(shí)的高度)
有些時(shí)候,我們需要知道當(dāng)前手機(jī)上是否顯示了NavigationBar,也就是屏幕底部的虛擬按鍵。這篇文章主要介紹了Android判斷NavigationBar是否顯示的方法(獲取屏幕真實(shí)的高度),需要的朋友可以參考下本文2017-01-01
android項(xiàng)目實(shí)現(xiàn)帶進(jìn)度條的系統(tǒng)通知欄消息
本篇文章主要介紹了android項(xiàng)目實(shí)現(xiàn)帶進(jìn)度條的系統(tǒng)通知欄消息,就是實(shí)現(xiàn)在通知欄看到下載進(jìn)度。具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下。2016-10-10
Android實(shí)現(xiàn)快遞物流跟蹤布局效果
本篇文章主要介紹了Android實(shí)現(xiàn)快遞跟蹤布局效果,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-05-05

