Android實現(xiàn)動態(tài)自動匹配輸入的內(nèi)容
本文實例為大家分享了Android實現(xiàn)動態(tài)自動匹配輸入內(nèi)容的具體代碼,供大家參考,具體內(nèi)容如下
用這兩個控件



分別實現(xiàn)這兩個:
package com.example.autocomplete;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.MultiAutoCompleteTextView;
public class MainActivity extends Activity {
private AutoCompleteTextView acTextView;
private String[] res = {"xxz1","xxz2","xxz3","shanghai1","shanghai2"};
private MultiAutoCompleteTextView MulacTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
acTextView = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1);
//需要適配器
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,res);
//初始數(shù)據(jù)源,去匹配文本框中輸入的內(nèi)容,然后綁定
acTextView.setAdapter(adapter);
MulacTextView = (MultiAutoCompleteTextView) findViewById(R.id.multiAutoCompleteTextView1);
MulacTextView.setAdapter(adapter);
//設(shè)置以逗號為分隔符結(jié)束的符號
MulacTextView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
}
布局文件:
<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:hint="請輸入搜索的關(guān)鍵詞"
android:completionThreshold="3"
android:id="@+id/autoCompleteTextView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
</AutoCompleteTextView>
<MultiAutoCompleteTextView
android:hint="請輸入搜索的郵件關(guān)鍵詞"
android:id="@+id/multiAutoCompleteTextView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</MultiAutoCompleteTextView>
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CheckBox" />
</LinearLayout>
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
android判斷設(shè)備是否有相機(jī)的實例代碼
下面小編就為大家?guī)硪黄猘ndroid判斷設(shè)備是否有相機(jī)的實例代碼。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-03-03
Flutter基本組件Basics?Widget學(xué)習(xí)
本文詳細(xì)講解了Flutter基本組件Basics?Widget,文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-12-12
Android自定義view實現(xiàn)滑動解鎖九宮格控件
這篇文章主要介紹了Android自定義view實現(xiàn)滑動解鎖九宮格控件,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧2023-02-02
Android使用NestedScrollView?內(nèi)嵌RecycleView滑動沖突問題解決
這篇文章主要介紹了Android使用NestedScrollView?內(nèi)嵌RecycleView滑動沖突問題解決,文章圍繞主題展開詳細(xì)的內(nèi)容介紹,具有一定的參考價值,感興趣的小伙伴可以參考一下2022-06-06
Android中實現(xiàn)自動生成布局View的初始化代碼方法
這篇文章主要介紹了Android中實現(xiàn)自動生成布局View的初始化代碼方法,本文使用解析layout 布局文件的方法實現(xiàn)需求,需要的朋友可以參考下2014-10-10
Android使用Notification實現(xiàn)寬視圖通知欄(二)
這篇文章主要為大家詳細(xì)介紹了Android使用Notification實現(xiàn)寬視圖通知欄,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-12-12

