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