How do I pass extra variables during a search invoked by a SearchView/ Widget?

前端 未结 3 1108
一整个雨季
一整个雨季 2021-02-13 12:55

I am successfully using a search widget in my action bar to perform a search following this guide. The search is fine, but I\'m wondering how to pass additional variables on a s

3条回答
  •  天命终不由人
    2021-02-13 13:27

    You can override the onSearchRequested method inside the Activity that's invoking the search.

    @Override
    public boolean onSearchRequested() {
         Bundle appData = new Bundle();
         appData.putBoolean(SearchableActivity.JARGON, true);
         startSearch(null, false, appData, false);
         return true;
     }
    

    then you can extract this data inside the SearchableActivity

    Bundle appData = getIntent().getBundleExtra(SearchManager.APP_DATA);
    if (appData != null) {
        boolean jargon = appData.getBoolean(SearchableActivity.JARGON);
    }
    

提交回复
热议问题