Majid
Majid

Reputation: 229

menu is not shown unless group activity is focussed

menu option not visible on menu btn click unless it is focussed.


       @Override 
    public boolean onCreateOptionsMenu(Menu menu) {
        // TODO Auto-generated method stub
    System.out.println(" in menu");     
    new MenuInflater(this.getParent()).inflate(R.menu.sample, menu);
        return (super.onCreateOptionsMenu(menu));

    }    

Upvotes: 1

Views: 851

Answers (2)

Bandreid
Bandreid

Reputation: 2733

try reading this blog post: http://ericharlow.blogspot.com/2010/09/experience-multiple-android-activities.html.

If the menu doesn't come up in the sub-activities of your ActivityGroup simply override the onCreateOptionsMenu and onOptionsItemSelected methods in your ActivityGroup to call the corresponding method of your current sub-activity.

Here is what you need to add in your ActivityGroup class:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    return this.getCurrentActivity().onCreateOptionsMenu(menu);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    return this.getCurrentActivity().onOptionsItemSelected(item);
}

That's it. Now implement these methods in each of your sub-activities to your liking and it should work just fine.

Upvotes: 3

kai
kai

Reputation: 101

log in onKeyDown method on every your group activity when press menu then you can trace what's going on

there must be a activity receive keypress event, you should take a look and you can see this article

parent ActivityGroup:

  @Overridepublic boolean onCreateOptionsMenu(Menu menu) {
      Log.d(TAG, "in parent");
  menu.clear();
  return getCurrentActivity().onCreateOptionsMenu(menu);

}


child ActivityGroup:

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_gionew, menu);
    Log.d(TAG, "in childA");
    return true;
}

Upvotes: 0

Related Questions