Android实现搜索功能 AutoCompleteTextView和MultiAutoCompleteTextView的用法
2016-08-07 12:25
375 查看
AutoCompleteTextView和MultiAutoCompleteTextView的用法:AutoCompleteTextView一般用在搜索框的使用,MultiAutoCompleteTextView一般使用在短信和邮件中。具体实现通过一个例子说明问题:
private AutoCompleteTextView acCompleteTextView; private MultiAutoCompleteTextView mactv; private String[] str = {"beijing","beijing tiananmen", "shanghai", "shanghai dongfangmingzhu", "lanzhou", "lanzhouzhongshanqiao", "lanzhou wuquanshan"}; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); acCompleteTextView = (AutoCompleteTextView) this.findViewById(R.id.acTextView); mactv = (MultiAutoCompleteTextView) this.findViewById(R.id.mactv); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,str); acCompleteTextView.setAdapter(adapter); mactv.setAdapter(adapter); /* 设置逗号为分隔符 */ mactv.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer()); }布局文件中的内容为:
<AutoCompleteTextView android:id="@+id/acTextView" android:layout_width="match_parent" android:layout_height="wrap_content" android:completionThreshold="2" android:hint="@string/content" /> <MultiAutoCompleteTextView android:id="@+id/mactv" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="@string/content" android:completionThreshold="2"/>
completionThreshold 属性的意思是从第几个字符开始自动匹配,我设置成了从第二个字符开始自动匹配。
相关文章推荐
- Android实现ListView的A-Z字母排序和过滤搜索功能,实现汉字转成拼音
- Android实现ListView的A-Z字母排序和过滤搜索功能,实现汉字转成拼音
- Android 实现ListView的A-Z字母排序和过滤搜索功能,实现汉字转成拼音
- Android - TabHost 选项卡功能用法详解&&TabWidget切换卡的实现应用&&实例说明
- Android 实现ListView的A-Z字母排序和过滤搜索功能,实现汉字转成拼音
- android代码实现搜索机身应用的功能
- Android 实现ListView的A-Z字母排序和过滤搜索功能,实现汉字转成拼音
- Android 实现ListView的A-Z字母排序和过滤搜索功能,实现汉字转成拼音
- Android 实现ListView的A-Z字母排序和过滤搜索功能,实现汉字转成拼音
- Android 实现ListView的A-Z字母排序和过滤搜索功能,实现汉字转成拼音
- Android实现ListView的A-Z字母排序和过滤搜索功能,实现汉字转成拼音
- Android ListView 自定义用法(ListView 实现单选功能)
- Android - TabHost 选项卡功能用法详解&&TabWidget切换卡的实现应用&&实例说明
- android实现关键字搜索功能
- Android 实现ListView的A-Z字母排序和过滤搜索功能,实现汉字转成拼音
- Android实现ListView的A-Z字母排序和过滤搜索功能,实现汉字转成拼音
- 举例说明android中SmsManager的用法---用来实现手机发送短信的功能
- Android----android利用数据库实现搜索联想功能
- Android 实现ListView的A-Z字母排序和过滤搜索功能,实现汉字转成拼音
- Android:实现ListView的A-Z字母排序和过滤搜索功能,实现汉字转成拼音