I'm trying to implement SearchWidget
correctly, but I'm facing up with some problems. I override onSearchRequested()
because I need to pass some information's from the calling Activity to the Activity
that executes the query.
It happens only when the SearchWidget
looses its "focus". This is what I mean for "focused" SearchWidget
:
If I search without touching outside the SearchWidget
(and so with the focuses SearchWidget
) onSearchRequested()
is correctly called.
BUT when I touch outside the SearchWidget
and it looses it focus, when I perform the search, the method onSearchRequested()
is not called.
This is the code of onSearchRequested
:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.actionbar_mainscreen, menu);
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
mSearchItem = menu.findItem(R.id.search);
mSearchView = (SearchView) mSearchItem.getActionView();
mSearchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
mSearchView.setIconifiedByDefault(true);
return true;
}
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()){
case R.id.search:
onSearchRequested();
break;
case R.id.mainscreen_favorites:
Intent intent = new Intent(this, FavoritesActivity.class);
startActivity(intent);
break;
}
return true;
}
@Override
public boolean onSearchRequested() {
Bundle appData = new Bundle();
appData.putInt(Constants.EXTRA_CATEGORY, index);
startSearch(null, false, appData, false);
return true;
}