SearchWidget does not call onSearchRequested ()

I got activity using searchwidget and listview. If someone is looking, all items that do not match the query should be removed, of course. Therefore, I want to delete all elements of the list and fill it with a smaller list. So I tried passing my ArrayList to a new search operation by adding it to the Bundle in the onSearchRequested method. But this method is not called when I do a search.

This is the code I received:

@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.sign_player); // Associate searchable configuration with the SearchView SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); SearchView searchView = (SearchView) findViewById(R.id.sv_sign_search_name); searchView.setSearchableInfo(searchManager .getSearchableInfo(getComponentName())); searchView.setIconifiedByDefault(false); searchView.setFocusable(false); // Get the intent, verify the action and get the query Intent intent = getIntent(); if (Intent.ACTION_SEARCH.equals(intent.getAction())) { String query = intent.getStringExtra(SearchManager.QUERY); Bundle bundle = intent.getBundleExtra(SearchManager.APP_DATA); player = bundle.getParcelableArrayList("players"); player = searchPlayers(query); showPlayers(); } else { initializeScreen(); } } @Override public boolean onSearchRequested() { Bundle appData = new Bundle(); appData.putParcelableArrayList("players", player); startSearch(null, false, appData, false); return true; } 
+4
source share
1 answer

You need to specify the metadata in your manifest to customize the search. For instance:

 <activity android:name=".activity.SuperDuperActivity"> <meta-data android:name="android.app.default_searchable" android:value=".activity.SearchResultsActivity"/> </activity> 

Then your SuperDuperActivity onSearchRequested () will certainly be called.

0
source

Source: https://habr.com/ru/post/1435747/


All Articles