The example of this article describes the Android implementation of the tab to add menu method. Share to everyone for your reference, specific as follows:
In Android, a menu-related method is not available in the Tabactivity class, so you cannot create a menu item if you are developing by using tabactivity alone. To add a menu to the tab, there are two ways:
1. The main event inherits the activity. This allows you to override the Oncreateoptionsmenu method directly in the main event to add menu to the program. If you need to have a different menu for each tab, you can add a ontabchangedlistener to the tabhost, which modifies a global variable (such as Intmenunumber) in this listener. This allows you to switch () the variable at Oncreateoptionsmenu, and you can add different menu for different tabs.
The advantage of this method is that if all tabs share a menu, the method is simple.
method Disadvantage: The Main event class is very large, and if each tab uses a different menu, the steps will be cumbersome.
2. Master event inherits Tabactivity, and then you need to use the menu tab to create a new inherited from activity event that is invoked using SetContent (new Intent (). SetClass (This, Newactivity.class)) method can be. As a result, each new activity can rewrite the Oncreateoptionsmenu method itself, adding the process will be very flexible.
method Advantage: It is easy to develop a separate menu for each tab, and the development process is more flexible.
method Disadvantage: The data Communication between tab and tab is more complicated.
For more information on Android-related content readers can view the site topics: "Android Development Introduction and Advanced Course", "Android Programming activity Operating Skills Summary", "Android Resource Operation skills Summary", "Android File operating skills summary" , "Android Operation SQLite Database Skills Summary", "Android operation JSON format Data Skills summary", "Android Database Operation skills Summary", "Android programming development of SD card operation method Summary", " Android View tips Summary and a summary of the use of Android controls
I hope this article will help you with the Android program.