Android Tutorial

(avery) #1

By : Ketan Bhimani


252 

TextView tv = new TextView(this);
Date now = new Date();
tv.setText(“I‟m from a factory. Created: “



  • now.toString());
    tv.setTextSize((float) 24);
    return (tv);
    } else {
    return null;
    }}}


This example creates a tabbed layout view with four tabs on it, as
shown in Figure. The first tab is from the recent GridView sample.
The second tab is from the ListView sample before that. The third
tab is the basic layout with two TextView objects, fully defined in an
XML layout file as previously demonstrated. Finally, the fourth tab
is created with a factory.

Four tabs displayed.

The first action is to get the TabHost
instance. This is the object that enables us
to add Intent objects and View identifiers
for drawing the screen. A TabActivity
provides a method to retrieve the current
TabHost object.

The next action is only loosely related to
tab views. The LayoutInflater is used to
turn the XML definition of a View into the
actual View objects. This would normally
happen when calling setContentView(),
but we’re not doing that. The use of the
LayoutInflater is required for referencing
the View objects by identifier, as is done for the third tab.
Free download pdf