http://www.cnblogs.com/keyindex/articles/1815074.html
这段时间在研究android平台上的开源项目——StandupTimer,这是由jwood所设计的一个较为简单android应用,用于控制会议时间,类似秒表倒计时。
<? xml version="1.0" encoding="utf-8" ?> < TabHost xmlns:android ="http://schemas.android.com/apk/res/android" android:id ="@android:id/tabhost" android:layout_width ="fill_parent" android:layout_height ="fill_parent" > < LinearLayout android:orientation ="vertical" android:layout_width ="fill_parent" android:layout_height ="fill_parent" > < TabWidget android:id ="@android:id/tabs" android:layout_width ="fill_parent" android:layout_height ="wrap_content" /> < FrameLayout android:id ="@android:id/tabcontent" android:layout_width ="fill_parent" android:layout_height ="fill_parent" > <!-- 省略部分代码 --> < TextView android:id ="@+id/no_team_meetings" android:textSize ="18sp" android:layout_width ="fill_parent" android:layout_height ="fill_parent" /> < TextView android:id ="@+id/no_team_meeting_stats" android:textSize ="18sp" android:layout_width ="fill_parent" android:layout_height ="fill_parent" /> </ FrameLayout > </ LinearLayout > </ TabHost >
private void createTabs() { TabHost tabhost = getTabHost(); tabhost.addTab(tabhost.newTabSpec( " stats_tab " ). setIndicator( this .getString(R.string.stats)). setContent(createMeetingDetails(team))); tabhost.addTab(tabhost.newTabSpec( " meetings_tab " ). setIndicator( this .getString(R.string.meetings)). setContent(createMeetingList())); getTabHost().setCurrentTab( 0 ); }
SDK上的原文:mTabHost = (TabHost)findViewById(R.id.tabhost); mTabHost.setup(); mTabHost.addTab(TAB_TAG_1, " Hello, world! " , " Tab 1 " );
Call setup() before adding tabs if loading TabHost using findViewById().However:You do not need to call setup() after getTabHost() inTabActivity
.
private TabContentFactory createMeetingDetails(Team team2) { return new TabHost.TabContentFactory() { @Override public View createTabContent(String tag) { //设置View setStatsTabContent(); return findViewById(R.id.teamStats); } }; } private TabHost.TabContentFactory createMeetingList() { return new TabHost.TabContentFactory() { @Override public View createTabContent(String tag) {meetingListAdapter = createMeetingListAdapter(); meetingList.setAdapter(meetingListAdapter); return meetingList; } }; }
private ListView meetingList = null ; private ArrayAdapter < String > meetingListAdapter = null ;
public class Tabs2 extends TabActivity implements TabHost.TabContentFactory
@Override public View createTabContent(String tag) { final TextView tv = new TextView( this ); tv.setText( " Content for tab with tag " + tag); return tv; }
private void setStatsTabContent() { if (team != null && team.hasMeetings( this )) { MeetingStats stats = team.getAverageMeetingStats(TeamDetailsActivity. this ); ((TextView) findViewById(R.id.meeting_team_name_label)).setText(getString(R.string.team_name)); ((TextView) findViewById(R.id.meeting_team_name)).setText(team.getName()); ((TextView) findViewById(R.id.number_of_meetings_label)).setText(getString(R.string.number_of_meetings)); ((TextView) findViewById(R.id.number_of_meetings)).setText(Integer.toString(( int ) team.getNumberOfMeetings(TeamDetailsActivity. this ))); ((TextView) findViewById(R.id.avg_number_of_participants_label)).setText(getString(R.string.avg_number_of_participants)); ((TextView) findViewById(R.id.avg_number_of_participants)).setText(Float.toString(stats.getNumParticipants())); ((TextView) findViewById(R.id.avg_meeting_length_label)).setText(getString(R.string.avg_meeting_length)); ((TextView) findViewById(R.id.avg_meeting_length)).setText(TimeFormatHelper.formatTime(stats.getMeetingLength())); ((TextView) findViewById(R.id.avg_individual_status_length_label)).setText(getString(R.string.avg_individual_status_length)); ((TextView) findViewById(R.id.avg_individual_status_length)).setText(TimeFormatHelper.formatTime(stats.getIndividualStatusLength())); ((TextView) findViewById(R.id.avg_quickest_status_label)).setText(getString(R.string.avg_quickest_status)); ((TextView) findViewById(R.id.avg_quickest_status)).setText(TimeFormatHelper.formatTime(stats.getQuickestStatus())); ((TextView) findViewById(R.id.avg_longest_status_label)).setText(getString(R.string.avg_longest_status)); ((TextView) findViewById(R.id.avg_longest_status)).setText(TimeFormatHelper.formatTime(stats.getLongestStatus())); } else { ((TextView) findViewById(R.id.meeting_team_name_label)).setText(getString(R.string.no_meeting_stats)); ((TextView) findViewById(R.id.meeting_team_name)).setText( "" ); ((TextView) findViewById(R.id.number_of_meetings_label)).setText( "" ); ((TextView) findViewById(R.id.number_of_meetings)).setText( "" ); ((TextView) findViewById(R.id.avg_number_of_participants_label)).setText( "" ); ((TextView) findViewById(R.id.avg_number_of_participants)).setText( "" ); ((TextView) findViewById(R.id.avg_meeting_length_label)).setText( "" ); ((TextView) findViewById(R.id.avg_meeting_length)).setText( "" ); ((TextView) findViewById(R.id.avg_individual_status_length_label)).setText( "" ); ((TextView) findViewById(R.id.avg_individual_status_length)).setText( "" ); ((TextView) findViewById(R.id.avg_quickest_status_label)).setText( "" ); ((TextView) findViewById(R.id.avg_quickest_status)).setText( "" ); ((TextView) findViewById(R.id.avg_longest_status_label)).setText( "" ); ((TextView) findViewById(R.id.avg_longest_status)).setText( "" ); } }
tabhost.addTab(tabhost.newTabSpec( " stats_tab " ) .setIndicator( this .getString(R.string.stats)) .setContent(createMeetingDetails(team)));
apiDemo也有3个例子可以参考。