[英]Multiple searchable activities with suggestions
我有兩個活動的應用程序 - 兩個不同的列表視圖與不同的數據,我想通過操作欄搜索兩者。 此外,兩者都應包含建議支持。
到目前為止,我似乎只有一個searchable.xml,它總是只綁定到一個活動:
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="@string/app_name"
android:hint="@string/search_hint"
android:searchSuggestAuthority="XXXSuggestionsContentProvider"
android:searchSuggestIntentAction="android.intent.action.VIEW">
</searchable>
有沒有辦法可以有多個搜索?
謝謝。
你可以試試這個,對我來說非常合適。
在活動中像這樣膨脹菜單。
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
MenuItem searchItem = menu.findItem(R.id.action_search);
SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String text) {
//REFRESH ADAPTER WITH NEW FILTERED LIST HERE
return false;
}
@Override
public boolean onQueryTextChange(String text) {
//REFRESH ADAPTER WITH NEW FILTERED LIST HERE
return false;
}
});
return true;
}
菜單應該看起來像這樣工作:
<menu
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:grupete="http://schemas.android.com/apk/res-auto" >
<item
android:id="@+id/action_search"
android:icon="@android:drawable/ic_menu_search"
grupete:actionViewClass="android.support.v7.widget.SearchView"
android:orderInCategory="100"
android:title="@string/search"
grupete:showAsAction="ifRoom"/>
</menu>
希望我能幫助你!
最好的祝福,
pedrovic90
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.