Sunday, 3 April 2011

Android tabs - One activity per tab or not?

Unlike other layout, the tab layout (tab host) is a little more complicated than others.

It requires:
  • XML File
    • General
      • TabHost (Main container)
      • TabWidget (Navigation between tabs):
      • FrameLayout (For the contents)
    • Behaviour (Optional)
      • Used for the behaviour of the tabs when it is selected or not.
  • Java File
    • Tab Activity
      • Extends TabActivity
      • Used to coordinate the action between the tabs
    • Activity
      • Extends Activity
      • Could be one single file for all the tabs or one for each of the activities
      • Called inside of Tab Activity by Intents
Here you can find some tutorial:
Official android development guide: (Not work for me)
Android People: (Simple but works)

  • Once the main.xml is done, it shouldn't be modified. If you want to set a layout inside the tab, you can do:
    • 1. Create a layoout (xml File) inside of res/layout (for example, "example.xml")
    • 2. In the activity of the corresponding tab, call the layout:
  • The id of the elements that has been set in different layout file are general for all the activities. You can differ a element from a layout to another one by adding the name of the layout at beginning.  For example, if you have two buttons which is called "checkout" both in the "coop" tab and in the "ICA" tab, you can name the coop's one "coopCheckout" and name the ICA's one "ICACheckout".

1 comment:

  1. In hello-tabwidget example you should put activities in your manifest file like this:

    It works right.