Android 郵箱自動補(bǔ)全-MultiAutoCompleteTextView實現(xiàn)

發(fā)布時間:2024-03-13
因為項目需要,要寫一個郵箱自動補(bǔ)全的edittext,剛開始考慮使用autocompletetextview來實現(xiàn),但是滿足不到需求官方組件太low了。。。
先來介紹下autocompletetextview 的使用:
activity
import android.os.bundle; import android.support.v7.app.appcompatactivity; import android.widget.arrayadapter; import android.widget.autocompletetextview; public class mainactivity extends appcompatactivity { private static final string[] countries = new string[]{ "belgium", "france", "italy", "germany", "spain" }; private autocompletetextview mautocompletetextview; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); mautocompletetextview = (autocompletetextview) findviewbyid(r.id.autocompletetextview); arrayadapter<string> adapter = new arrayadapter(this, android.r.layout.simple_dropdown_item_1line, countries); mautocompletetextview.setadapter(adapter); } }
xml
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margintop="20dp" android:text="autocompletetextview實現(xiàn)" android:textcolor="@android:color/black" /> <autocompletetextview android:id="@ id/autocompletetextview" android:layout_width="match_parent" android:layout_height="wrap_content" android:completionthreshold="1"/> </linearlayout>
使用方法很簡單,獲取到組件然后設(shè)置一個彈出的adapter就能完成一個自動提示。
但是這個組件有幾個特性不是很滿足我們的需求。
1.默認(rèn)是第二個字母開始匹配
2.整體內(nèi)容匹配模式 belgium 我們只能輸入b ,be,bel等才會匹配
注:郵箱格式為123456@xx.com,整體內(nèi)容肯定不行。
下面我們又看到一個multiautocompletetextview組件,來看下multiautocompletetextview能否滿足我們的需求
import android.os.bundle; import android.support.v7.app.appcompatactivity; import android.widget.arrayadapter; import android.widget.autocompletetextview; import android.widget.multiautocompletetextview; public class mainactivity extends appcompatactivity { private static final string[] countries = new string[]{ "belgium", "france", "italy", "germany", "spain" }; private autocompletetextview mautocompletetextview; private multiautocompletetextview mmultiautocompletetextview; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); mautocompletetextview = (autocompletetextview) findviewbyid(r.id.autocompletetextview); mmultiautocompletetextview = (multiautocompletetextview) findviewbyid(r.id.multiautocompletetextview); arrayadapter<string> adapter = new arrayadapter(this, android.r.layout.simple_dropdown_item_1line, countries); mautocompletetextview.setadapter(adapter); mmultiautocompletetextview.setadapter(adapter); mmultiautocompletetextview.settokenizer(new multiautocompletetextview.commatokenizer()); } }
xml
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margintop="20dp" android:text="autocompletetextview實現(xiàn)"
上一個:個人用筆記本電腦推薦哪款好,筆記本電腦哪個好
下一個:征信大數(shù)據(jù)免費查詢平臺,哪里可查大數(shù)據(jù)征信

RC-02K9101FT,F(xiàn) 0402 9.1K現(xiàn)貨購買,風(fēng)華 0402 9.1KΩ ±1% 1/16W
阿里云服務(wù)器怎么看內(nèi)存什么的
異地離婚訴訟手續(xù)
閩北綠色食品茶葉可持續(xù)發(fā)展與管理措施
君子蘭花期前后管理護(hù)理
排線卡扣怎么拆,前面板的排線怎么拆
荷花的播種繁育初探
阿里云備案買服務(wù)器
華碩a555l什么時候上市的(華碩a555q配置參數(shù))
win10家庭版怎么關(guān)閉自動更新系統(tǒng)更新(window10家庭版關(guān)閉自動更新)
十八禁 网站在线观看免费视频_2020av天堂网_一 级 黄 色 片免费网站_绝顶高潮合集Videos