Android實(shí)現(xiàn)自動(dòng)文本框提示功能
本文實(shí)例為大家分享了Android實(shí)現(xiàn)自動(dòng)文本框提示的具體代碼,供大家參考,具體內(nèi)容如下

activity_main.xml布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<!--
默認(rèn)輸2個(gè)字符才能有提示
completionThreshold表示只輸入1個(gè)字符后,就有提示
requestFocus表示界面展開(kāi)時(shí)焦點(diǎn)直接在第二個(gè)文本框
-->
<AutoCompleteTextView
android:id="@+id/myTextView01"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:completionThreshold="1" />
<MultiAutoCompleteTextView
android:id="@+id/myTextView02"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:completionThreshold="1">
<requestFocus />
</MultiAutoCompleteTextView>
</LinearLayout>
代碼實(shí)現(xiàn)
public class MainActivity extends Activity {
private AutoCompleteTextView myTextView01;
private MultiAutoCompleteTextView myTextView02;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myTextView01 = (AutoCompleteTextView) findViewById(R.id.myTextView01);
myTextView02 = (MultiAutoCompleteTextView) findViewById(R.id.myTextView02);
String[] str={"xiaohe","xiaowang","xiaoli","zhanghe","zhangmin","zhaojun","lihe","daming"};
/*
* 創(chuàng)建適配器
* 參數(shù)一:上下文
* 參數(shù)二:提示下位框的樣式,不喜歡可以換android.R.layout.*
* 參數(shù)三:下拉框中備選的內(nèi)容
*/
ArrayAdapter<String> adapter=new ArrayAdapter<String>(
this,
android.R.layout.simple_dropdown_item_1line,
str);
//將Adapter設(shè)置到AutoCompleteTextView中
myTextView01.setAdapter(adapter);
myTextView02.setAdapter(adapter);
//以","作為分隔符
myTextView02.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
}
}
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Android自動(dòng)編輯文本框(AutoCompleteTextView)使用方法詳解
- Android AutoCompleteTextView自動(dòng)提示文本框?qū)嵗a
- Android自動(dòng)文本框輸入識(shí)別提示功能代碼
- Android中EditText和AutoCompleteTextView設(shè)置文字選中顏色方法
- Android中AutoCompleteTextView與MultiAutoCompleteTextView的用法
- Android AutoCompleteTextView控件使用實(shí)例
- 基于Android中的 AutoCompleteTextView實(shí)現(xiàn)自動(dòng)填充
- 實(shí)例講解Android中的AutoCompleteTextView自動(dòng)補(bǔ)全組件
- Android AutoCompleteTextView連接數(shù)據(jù)庫(kù)自動(dòng)提示的方法(附demo源碼下載)
- Android高級(jí)組件AutoCompleteTextView自動(dòng)完成文本框使用詳解
相關(guān)文章
Android實(shí)現(xiàn)帶有記住密碼功能的登陸界面
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)帶有記住密碼功能的登陸界面,主要采用SharedPreferences來(lái)保存用戶數(shù)據(jù),感興趣的小伙伴們可以參考一下2016-05-05
Android跨進(jìn)程拋異常的原理的實(shí)現(xiàn)
這篇文章主要介紹了Android跨進(jìn)程拋異常的原理的實(shí)現(xiàn),小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-11-11
解決android studio android monitor打不開(kāi)的問(wèn)題
下面小編就為大家分享一篇解決android studio android monitor打不開(kāi)的問(wèn)題,具有很的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-01-01
Android小程序?qū)崿F(xiàn)個(gè)人信息管理系統(tǒng)
這篇文章主要為大家詳細(xì)介紹了Android小程序?qū)崿F(xiàn)個(gè)人信息管理系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-05-05
詳解Android使用Html.fromHtml需要注意的地方
本篇文章主要介紹了詳解Android使用Html.fromHtml需要注意的地方,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-07-07
Flutter 枚舉值enum和int互相轉(zhuǎn)化總結(jié)
這篇文章主要為大家介紹了Flutter 枚舉值enum和int互相轉(zhuǎn)化總結(jié)分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-02-02
Eclipse工程轉(zhuǎn)為兼容Android Studio模式的方法步驟圖文詳解
這篇文章主要介紹了Eclipse工程轉(zhuǎn)為兼容Android Studio模式的方法步驟,本文圖文并茂給大家介紹的非常詳細(xì),需要的朋友可以參考下2017-12-12
android中intent傳遞list或者對(duì)象的方法
這篇文章主要介紹了android中intent傳遞list或者對(duì)象的方法,分析羅列了常用的幾種方法,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-01-01

