我做了一个搜索小部件,工作正常。但是当我按下后退按钮时,onCancel和onDismiss永远不会调用。
在PCRListActivity.java中:
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.list, menu);
// Get the SearchView and set the searchable configuration
SearchManager searchManager = (SearchManager) this.getSystemService(Context.SEARCH_SERVICE);
SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();
// Assumes current activity is the searchable activity
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
searchView.setIconifiedByDefault(false); // Do not iconify the widget; expand it by default
searchManager.setOnCancelListener(new SearchManager.OnCancelListener() {
@Override
public void onCancel() {
getLoaderManager().restartLoader(LOADER_ID_PRODUCTS, null, PCRListActivity.this);
}
});
searchManager.setOnDismissListener(new SearchManager.OnDismissListener() {
@Override
public void onDismiss() {
getLoaderManager().restartLoader(LOADER_ID_PRODUCTS, null, PCRListActivity.this);
}
});
return true;
}
那么,我做错了什么?
答案 0 :(得分:0)
我也遇到了这个问题,我别无选择,只能放弃“oncloselistener”。相反,您可以获取menuItem,然后是setOnActionExpandListener。然后覆盖unimplents方法。 我想close和dissmiss方法只适用于Progress Dialogs。
@Override
public boolean onMenuItemActionExpand(MenuItem item) {
// TODO Auto-generated method stub
return true;
}
@Override
public boolean onMenuItemActionCollapse(MenuItem item) {
//do what you want to when close the sesarchview
//remember to return true;
return true;
}