Android實(shí)現(xiàn)動態(tài)自動匹配輸入的內(nèi)容
更新時間:2018年08月10日 08:37:07 作者:流年若逝
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)動態(tài)自動匹配輸入的內(nèi)容,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實(shí)例為大家分享了Android實(shí)現(xiàn)動態(tài)自動匹配輸入內(nèi)容的具體代碼,供大家參考,具體內(nèi)容如下
用這兩個控件



分別實(shí)現(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)文章
Android6.0藍(lán)牙出現(xiàn)無法掃描設(shè)備或閃退問題解決辦法
這篇文章主要介紹了Android6.0藍(lán)牙出現(xiàn)無法掃描設(shè)備或閃退問題解決辦法的相關(guān)資料,需要的朋友可以參考下2017-02-02
Flutter實(shí)現(xiàn)旋轉(zhuǎn)掃描效果
這篇文章主要介紹了通過Flutter RotationTransition實(shí)現(xiàn)雷達(dá)旋轉(zhuǎn)掃描的效果,文中的示例代碼講解詳細(xì),感興趣的同學(xué)可以動手試一試2022-01-01
Android 仿抖音的評論列表的UI和效果的實(shí)現(xiàn)代碼
抖音是一款音樂創(chuàng)意短視頻社交軟件,此app已在android各大應(yīng)用商店和app store 上線。下面小編給大家?guī)砹薃ndroid 仿抖音的評論列表的UI和效果的實(shí)現(xiàn)代碼,感興趣的朋友參考下吧2018-03-03
Android實(shí)現(xiàn)檢測手機(jī)搖晃的監(jiān)聽器
本文給大家分享一段代碼實(shí)現(xiàn)檢測手機(jī)搖晃的監(jiān)聽器,代碼簡單易懂,非常不錯,感興趣的朋友參考下吧2016-12-12
Android實(shí)現(xiàn)斷點(diǎn)下載的方法
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)斷點(diǎn)下載的方法,感興趣的小伙伴們可以參考一下2016-03-03

