我有一个带有搜索小部件和列表视图的活动。如果有人搜索,所有与查询不匹配的项目当然应该被删除。所以我想删除列表中的所有项目并用较小的列表填充它。因此,我尝试通过将 ArrayList 添加到 onSearchRequested 方法中的 Bundle 来将其传递给新的可搜索 Activity。但是当我执行搜索时不会调用此方法。
这是我得到的代码:
@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;
}