WEB开发网
开发学院手机开发Android 开发 Android UI学习 - Tab的学习和使用 阅读

Android UI学习 - Tab的学习和使用

 2010-05-18 16:38:00 来源:WEB开发网   
核心提示:createTabContent里面是不能调用getCurrentTabView等之类的函数的,否则就出错!至于Views/Tabs/Content By Intent例子,Android UI学习 - Tab的学习和使用(4),就只是贴出代码,不给截图了:public class Tabs3 extends TabA
createTabContent里面是不能调用getCurrentTabView等之类的函数的,否则就出错!

至于Views/Tabs/Content By Intent例子,就只是贴出代码,不给截图了:

public class Tabs3 extends TabActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); final TabHost tabHost = getTabHost(); tabHost.addTab(tabHost.newTabSpec("tab1") .setIndicator("list") .setContent(new Intent(this, List1.class))); tabHost.addTab(tabHost.newTabSpec("tab2") .setIndicator("photo list") .setContent(new Intent(this, List8.class))); // This tab sets the intent flag so that it is recreated each time // the tab is clicked. tabHost.addTab(tabHost.newTabSpec("tab3") .setIndicator("destroy") .setContent(new Intent(this, Controls2.class) .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))); } }

效果:Tab1的内容是List1的Activity,Tab2的是List8的Activity,Tab3的是 controls2.Activity。

TabHost.OnTabChangeListener

TabHost.OnTabChangeListener接口只有一个抽象方法onTabChanged(String tagString),明显地,在onTabChanged(String tagString)方法里面 swtich..case..来判断tagString分别处理就行了。

TabHost.setup()

在此贴出SDK doc里面的相关解释:

public void setup () Since: API Level 1

Call setup() before adding tabs if loading TabHost using findViewById(). However,You do not need to call setup() after getTabHost() in TabActivity. Example:

mTabHost = (TabHost)findViewById(R.id.tabhost);

mTabHost.setup();

mTabHost.addTab(TAB_TAG_1, "Hello, world!", "Tab 1");

//我的理解是,如果要用到findViewById来获取TabHost,然后add tabs的话,需要在addTab前call setup();

public void setup (LocalActivityManager activityGroup) Since: API Level 1

If you are using setContent(android.content.Intent), this must be called since the activityGroup is needed to launch the local activity. This is done for you if you extend TabActivity.

Parameters

activityGroup Used to launch activities for tab content.

上一页  1 2 3 4 

Tags:Android UI 学习

编辑录入:coldstar [复制链接] [打 印]
赞助商链接