源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

Android中AutoCompleteTextView与MultiAutoCompleteTextView的用法

  • 时间:2020-01-05 16:26 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:Android中AutoCompleteTextView与MultiAutoCompleteTextView的用法
本文以实例列举了Android中AutoCompleteTextView与MultiAutoCompleteTextView的使用方法,具体使用方法如下: 首先看[b]AutoCompleteTextView的使用:[/b] 支持基本的自动完成功能,适用在各种搜索功能中,并且可以根据自己的需求设置他的默认显示数据。 两个控件都可以很灵活的预置匹配的那些数据,并且可以设置输入多少值时开始匹配等等功能。 布局文件很简单,如下所示:
<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);
}
[b]MultiAutoCompleteTextView的使用:[/b] 该控件可支持选择多个值(在多次输入的情况下),分别用分隔符分开,并且在每个值选中的时候再次输入值时会自动去匹配。 可用在发短信,发邮件时选择联系人这种类型当中。 使用时需要执行设置分隔符方法。 MultiAutoCompleteTextView的使用和AutoCompleteTextView类似,只是需要设置分隔符: 具体的使用方法为在setAdapter()方法后添加:
mTextView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部