开发者

menu is not shown unless group activity is focussed

menu option not visible on menu b开发者_StackOverflowtn 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));

    }    


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.


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;
}

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜