Android 自動完成文本框的實例
Android:自動完成文本框
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 自動完成文本框的實例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
Android開發(fā)手冊自定義Switch開關(guān)按鈕控件
這篇文章主要為大家介紹了Android開發(fā)手冊自定義Switch開關(guān)按鈕控件的示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-06-06
Android開發(fā)之TimePicker控件用法實例詳解
這篇文章主要介紹了Android開發(fā)之TimePicker控件用法,結(jié)合實例形式詳細(xì)分析了Android項目的建立及TimePicker控件的具體使用技巧,需要的朋友可以參考下2016-02-02
Android Studio 新手入門教程(一)基本設(shè)置圖解
這篇文章主要介紹了Android Studio 新手入門教程(一)基本設(shè)置圖解,需要的朋友可以參考下2017-12-12
Android多設(shè)備多module打包fat-aar(最新推薦)
這篇文章主要介紹了Android多設(shè)備多module打包(fat-aar),本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2023-03-03
Fedora14下android開發(fā): eclipse與ibus確有沖突的問題分析
本篇文章是對Fedora14下android開發(fā),eclipse與ibus確有沖突的問題進行了分析介紹,需要的朋友參考下2013-05-05
Android判斷NavigationBar是否顯示的方法(獲取屏幕真實的高度)
有些時候,我們需要知道當(dāng)前手機上是否顯示了NavigationBar,也就是屏幕底部的虛擬按鍵。這篇文章主要介紹了Android判斷NavigationBar是否顯示的方法(獲取屏幕真實的高度),需要的朋友可以參考下本文2017-01-01
android項目實現(xiàn)帶進度條的系統(tǒng)通知欄消息
本篇文章主要介紹了android項目實現(xiàn)帶進度條的系統(tǒng)通知欄消息,就是實現(xiàn)在通知欄看到下載進度。具有一定的參考價值,感興趣的小伙伴們可以參考一下。2016-10-10

