我通过searchwidget和listview获得了一个活动。如果有人搜索,则当然应删除与查询不匹配的所有项目。所以我想删除列表中的所有项目,并用较小的列表填充它。所以我尝试将我的ArrayList传递给新的可搜索Activity,方法是将它添加到onSearchRequested方法的Bundle中。但是当我执行搜索时,不会调用此方法。
这是我得到的代码:
@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;
}
答案 0 :(得分:0)
您需要在Manifest中指定元数据以进行可搜索的活动设置。例如:
<activity android:name=".activity.SuperDuperActivity">
<meta-data
android:name="android.app.default_searchable"
android:value=".activity.SearchResultsActivity"/>
</activity>
然后在您的 SuperDuperActivity 中肯定会调用onSearchRequested()。