Android實(shí)現(xiàn)動(dòng)態(tài)自動(dòng)匹配輸入的內(nèi)容
本文實(shí)例為大家分享了Android實(shí)現(xiàn)動(dòng)態(tài)自動(dòng)匹配輸入內(nèi)容的具體代碼,供大家參考,具體內(nèi)容如下
用這兩個(gè)控件
分別實(shí)現(xiàn)這兩個(gè):
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è)置以逗號(hào)為分隔符結(jié)束的符號(hào) 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="請(qǐng)輸入搜索的關(guān)鍵詞" android:completionThreshold="3" android:id="@+id/autoCompleteTextView1" android:layout_width="match_parent" android:layout_height="wrap_content" > </AutoCompleteTextView> <MultiAutoCompleteTextView android:hint="請(qǐng)輸入搜索的郵件關(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>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Android6.0藍(lán)牙出現(xiàn)無(wú)法掃描設(shè)備或閃退問(wèn)題解決辦法
這篇文章主要介紹了Android6.0藍(lán)牙出現(xiàn)無(wú)法掃描設(shè)備或閃退問(wèn)題解決辦法的相關(guān)資料,需要的朋友可以參考下2017-02-02Flutter實(shí)現(xiàn)旋轉(zhuǎn)掃描效果
這篇文章主要介紹了通過(guò)Flutter RotationTransition實(shí)現(xiàn)雷達(dá)旋轉(zhuǎn)掃描的效果,文中的示例代碼講解詳細(xì),感興趣的同學(xué)可以動(dòng)手試一試2022-01-01Android 仿抖音的評(píng)論列表的UI和效果的實(shí)現(xiàn)代碼
抖音是一款音樂(lè)創(chuàng)意短視頻社交軟件,此app已在android各大應(yīng)用商店和app store 上線。下面小編給大家?guī)?lái)了Android 仿抖音的評(píng)論列表的UI和效果的實(shí)現(xiàn)代碼,感興趣的朋友參考下吧2018-03-03Android實(shí)現(xiàn)檢測(cè)手機(jī)搖晃的監(jiān)聽(tīng)器
本文給大家分享一段代碼實(shí)現(xiàn)檢測(cè)手機(jī)搖晃的監(jiān)聽(tīng)器,代碼簡(jiǎn)單易懂,非常不錯(cuò),感興趣的朋友參考下吧2016-12-12Android實(shí)現(xiàn)斷點(diǎn)下載的方法
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)斷點(diǎn)下載的方法,感興趣的小伙伴們可以參考一下2016-03-03