Android implements the tab Add menu method _android

Source: Internet
Author: User
Tags sqlite database

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.