Android--多選自動搜尋提示
2015-01-24 22:21
賀臣 閱讀(1122)
評論(0)
編輯 收藏
一. 效果圖
常見效果,在搜素提示選中之後可以繼續搜尋添加,選中的詞條用特殊字元分開

二. 布局代碼
<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" 删除或者替換為其他主題即可
- 分類 Android