Searchview In One Activity, Results In Another One
My use case is the following: in activity A, I have an action bar with a collapsible SearchView. When the user gives her query and presses the 'search' button, I would like to show
Solution 1:
According to Android documentations, SearchManager.getSearchableInfo(componentName)
takes one argument, which is:
componentName: The activity to get searchable information for
In your case you need ActivityB
, so constructing a ComponentName that points to ActivityB
is the correct way
newComponentName(this, ActivityB.class)
Solution 2:
<intent-filter><actionandroid:name="android.intent.action.SEARCH"/></intent-filter>
add this intent filter to activity A.
2.SearchView Menu
SearchManagersearchManager= (SearchManager) getSystemService(Context.SEARCH_SERVICE);
searchView = (SearchView) menu.findItem(R.id.search).getActionView();
searchView.setSearchableInfo(searchManager
.getSearchableInfo(getComponentName()));
xml:
<?xml version="1.0" encoding="utf-8"?><menuxmlns:android="http://schemas.android.com/apk/res/android" ><itemandroid:id="@+id/search"android:actionViewClass="android.widget.SearchView"android:icon="@drawable/ic_action_search"android:showAsAction="collapseActionView|always"android:title="@string/search_hint"/></menu>
3.Call this method from oncreate.
privatevoidhandleIntent(Intent intent) {
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
String query = intent.getStringExtra(SearchManager.QUERY);
Debug.e("Suggestion handle click", "call " + query);
startNextActivity(query);
}
}
4. if you are using Autosuggestion Listview implement searchView.setOnQueryTextListener ,setOnSuggestionListener and setSuggestionsAdapter.
Post a Comment for "Searchview In One Activity, Results In Another One"