Android code for getting Options Menu programmatically in android after displaying the Activity??
Is this possible?
Thanks in advance!!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I was able to open the menu by hooking the onAttachedToWindow() event. This would fire automatically after the view was created. I used the following code:
When I attempted to open the Option Menu in the “onCreate(…)” or “onPostCreate(…)” events, I received the following error: “Unable to add window — token null is not valid; is your activity running?” It seems that the Option Menu is not available until the view is being drawn and registered to the Window.
As an aside, it may be preferable to open the Options Menu by hooking the “onTouchEvent(Motion event)” as in:
This way, the Options Menu is displayed if the user taps or swipes the activity. To round out the discussion, the Option Menu may be dismissed via the following command:
((Activity) mContext).closeOptionsMenu();
Thus, the Options Menu can be “toggled” by using the following commands:
Well, I hope this helps.