no callback to onOptionsMenuClosed(). and getting error in overriding onPanelClosed() functions

拟墨画扇 提交于 2019-12-11 11:44:25

问题


I have a fragment which is made using PreferenceFragment ,where I am overriding onOptionsMenuClosed(). But , its the callback is not coming to it.Neither is the call back coming to OnMenuOpened(), OnPanelCosed()...

This is what i have alredy tired.

@Override
public void onOptionsMenuClosed(Menu menu) {
   // TODO Auto-generated method stub
   Log.e(TAG, "close optionmenu");
   super.onOptionsMenuClosed(menu);
}

and for onPanelClosed this is what i am trying.

@Override
public void onPanelClosed(int featureId, Menu menu) {
    Log.e(TAG,"on panel closed the feature id is vivek "+featureId);
    super.onPanelClosed(featureId, menu);
}

and when i do that for onPanelClosed(), Please help me out with this..

Please suggest where i am getting it wrong. and is tere any other way to catch if menu is closed without selecting any option.


回答1:


i finally found a solution for this :).. this is what is did.

public boolean isOverflowMenuOpen  = false;
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    Activity activity = getActivity();
    activity.getActionBar().addOnMenuVisibilityListener(new OnMenuVisibilityListener() {
    @Override
        public void onMenuVisibilityChanged(boolean isVisible) {
            // TODO Auto-generated method stub
            isOverflowMenuOpen = isOverflowMenuOpen ? false : true;
        }
    });

now from the variable isOverflowMenuOpen i can track if the overflow menu is open or not.



来源:https://stackoverflow.com/questions/24989278/no-callback-to-onoptionsmenuclosed-and-getting-error-in-overriding-onpanelclo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!