Android solves the problem that nested fragments cannot receive oncreateoptions menu events

preface

Nested Level 2 fragments cannot receive oncreateoptionsmenu events. Setting sethasoptionsmenu does not work.

text

Supplementary notes:

If you manually call the second level fragment by caching the fragment, inexplicable problems may occur, such as more menus are not displayed.

terms of settlement:

Add a menu in the first level fragment. You can manually call this method of the second level in the first level onoptionsitemselected to handle related events.

Example code:

Code Description:

The sample code is a first level fragment, and getfragmentbyposition returns a second level fragment.

The above is the problem that Android fragment cannot receive oncreateoptions menu events. I hope to help Android developers solve similar problems.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>