Android 邮箱自动补全-MultiAutoCompleteTextView实现

发布时间:2024-03-13
因为项目需要,要写一个邮箱自动补全的edittext,刚开始考虑使用autocompletetextview来实现,但是满足不到需求官方组件太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实现" android:textcolor="@android:color/black" /> <autocompletetextview android:id="@ id/autocompletetextview" android:layout_width="match_parent" android:layout_height="wrap_content" android:completionthreshold="1"/> </linearlayout>
使用方法很简单,获取到组件然后设置一个弹出的adapter就能完成一个自动提示。
但是这个组件有几个特性不是很满足我们的需求。
1.默认是第二个字母开始匹配
2.整体内容匹配模式 belgium 我们只能输入b ,be,bel等才会匹配
注:邮箱格式为123456@xx.com,整体内容肯定不行。
下面我们又看到一个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实现"
上一个:个人用笔记本电脑推荐哪款好,笔记本电脑哪个好
下一个:征信大数据免费查询平台,哪里可查大数据征信

RC-02K9101FT,F 0402 9.1K现货购买,风华 0402 9.1KΩ ±1% 1/16W
阿里云服务器怎么看内存什么的
异地离婚诉讼手续
闽北绿色食品茶叶可持续发展与管理措施
君子兰花期前后管理护理
排线卡扣怎么拆,前面板的排线怎么拆
荷花的播种繁育初探
阿里云备案买服务器
华硕a555l什么时候上市的(华硕a555q配置参数)
win10家庭版怎么关闭自动更新系统更新(window10家庭版关闭自动更新)