您的位置:首页 > 移动开发 > Android开发

Android--多选自动搜索提示

2015-01-24 22:21 302 查看
一. 效果图

  常见效果,在搜素提示选中之后可以继续搜索添加,选中的词条用特殊字符分开



二. 布局代码

<MultiAutoCompleteTextView
android:id="@+id/autoMulti"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginTop="50dp"
/>


三. 设置数据源

private void bind(){
MultiAutoCompleteTextView autoText=(MultiAutoCompleteTextView)findViewById(R.id.autoMulti);
ArrayAdapter<String> adapter=new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, items);
autoText.setAdapter(adapter);
autoText.setThreshold(1);
autoText.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
}


  此用法和上一篇的AutoCompleteTextView的用法基本一致,只是在后面添加了一个Token分割的问题

四. 测试中不显示搜索词条问题

  


  如上效果图,在搜索的词条中是存在的,搜索提示框也出现了,但是没有出现提示框中的内容,这样主要是因为Android主题导致的,因为颜色的冲突导致内容未能够显示出来

  解决方法如下:

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >


  将AndroidManifest.xml 文件中的如上代码 主题 android:theme="@style/AppTheme" 删除或者替换为其他主题即可
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: