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自帶的簡單布局 myStr); //資源數(shù)組 AutoCompleteTextView myAutoCompleteTextView = (AutoCompleteTextView) findViewById(R.id.myAutoCompleteTextView); //得到控件的引用 myAutoCompleteTextView.setAdapter(aa); //設(shè)置適配器 myAutoCompleteTextView.setThreshold(1); //定義需要用戶輸入的字符數(shù) } }
以上這篇Android 自動(dòng)完成文本框的實(shí)例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Android實(shí)現(xiàn)帶有指示器的進(jìn)度條
這篇文章主要介紹了Android實(shí)現(xiàn)帶有指示器的進(jìn)度條的示例代碼,幫助大家更好的理解和學(xué)習(xí)使用Android開發(fā),感興趣的朋友可以了解下2021-05-05使用Android studio查看Kotlin的字節(jié)碼教程
這篇文章主要介紹了使用Android studio查看Kotlin的字節(jié)碼教程,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-03-03Android 新手引導(dǎo)蒙層效果實(shí)現(xiàn)代碼示例
本篇文章主要介紹了Android 新手引導(dǎo)蒙層效果實(shí)現(xiàn)代碼示例,具有一定的參考價(jià)值,有興趣的可以了解一下。2017-01-01Android viewpager自動(dòng)輪播和小圓點(diǎn)聯(lián)動(dòng)效果
這篇文章主要為大家詳細(xì)介紹了Android viewpager自動(dòng)輪播和小圓點(diǎn)聯(lián)動(dòng)效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-10-10edittext + listview 實(shí)現(xiàn)搜索listview中的內(nèi)容方法(推薦)
下面小編就為大家?guī)硪黄猠dittext + listview 實(shí)現(xiàn)搜索listview中的內(nèi)容方法(推薦)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-03-03Android編程實(shí)現(xiàn)手繪及保存為圖片的方法(附demo源碼下載)
這篇文章主要介紹了Android編程實(shí)現(xiàn)手繪及保存為圖片的方法,涉及Android畫布的使用及圖片的操作技巧,并附帶了demo源碼供讀者下載,需要的朋友可以參考下2015-12-12Android 8.0升級不跳轉(zhuǎn)應(yīng)用安裝頁面的解決方法
這篇文章主要為大家詳細(xì)介紹了Android 8.0升級不跳轉(zhuǎn)應(yīng)用安裝頁面的解決方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-06-06Android 將網(wǎng)絡(luò)的Url資源轉(zhuǎn)換為Drawable資源方式
這篇文章主要介紹了Android 將網(wǎng)絡(luò)的Url資源轉(zhuǎn)換為Drawable資源方式,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-03-03