Android中AutoCompleteTextView与MultiAutoCompleteTextView的用法
本文以实例列举了Android中AutoCompleteTextView与MultiAutoCompleteTextView的使用方法,具体使用方法如下:
首先看AutoCompleteTextView的使用:
支持基本的自动完成功能,适用在各种搜索功能中,并且可以根据自己的需求设置他的默认显示数据。
两个控件都可以很灵活的预置匹配的那些数据,并且可以设置输入多少值时开始匹配等等功能。
布局文件很简单,如下所示:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<AutoCompleteTextView
android:id="@+id/tv"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
这里需要说明一下layout_width不应该设置为wrap_content,否则下拉提示只能看到第一个提示,后面的内容看不到。
业务代码如下:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mTextView = (AutoCompleteTextView)findViewById(R.id.tv);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line,autoStr);
mTextView.setAdapter(adapter);
}
MultiAutoCompleteTextView的使用:
该控件可支持选择多个值(在多次输入的情况下),分别用分隔符分开,并且在每个值选中的时候再次输入值时会自动去匹配。
可用在发短信,发邮件时选择联系人这种类型当中。
使用时需要执行设置分隔符方法。
MultiAutoCompleteTextView的使用和AutoCompleteTextView类似,只是需要设置分隔符:
具体的使用方法为在setAdapter()方法后添加:
mTextView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
- Android实现自动文本框提示功能
- Android自动编辑文本框(AutoCompleteTextView)使用方法详解
- Android AutoCompleteTextView自动提示文本框实例代码
- Android自动文本框输入识别提示功能代码
- Android中EditText和AutoCompleteTextView设置文字选中颜色方法
- Android AutoCompleteTextView控件使用实例
- 基于Android中的 AutoCompleteTextView实现自动填充
- 实例讲解Android中的AutoCompleteTextView自动补全组件
- Android AutoCompleteTextView连接数据库自动提示的方法(附demo源码下载)
- Android高级组件AutoCompleteTextView自动完成文本框使用详解
相关文章
Android studio 使用Debugger问题(代码中含有ndk)
这篇文章主要介绍了Android studio 使用Debugger问题(代码中含有ndk),非常不错,具有参考借鉴价值,需要的朋友可以参考下2017-11-11
Android编程实现的自定义弹窗(PopupWindow)功能示例
这篇文章主要介绍了Android编程实现的自定义弹窗(PopupWindow)功能,结合简单实例形式分析了Android自定义弹窗实现方法与相关注意事项,需要的朋友可以参考下2017-03-03
Android studio 3.0 查看手机文件系统的方法(超简单)
本文给大家分享Android studio更新到3.0版本之后,查看手机文件系统的方法,需要的朋友参考下吧2017-11-11
Android RecyclerView自定义上拉和下拉刷新效果
这篇文章主要为大家详细介绍了Android RecyclerView自定义上拉和下拉刷新效果,具有一定的参考价值,感兴趣的小伙伴们可以参考一下2017-02-02


最新评论