Java 类android.app.ActionBar.TabListener 实例源码

项目:android_programmering_2014    文件:SimpleTabListener.java   
public static void SetupTabbedNavigation(Activity containingActivity,
                                                           int displayNameResourceId,
                                                           int fragmentClassNameResourceId,
                                                           int viewGroupId) {
    // Load the display values and class names from the resources
    String[] displayNameList = containingActivity.getResources().getStringArray(displayNameResourceId);
    String[] fragmentList = containingActivity.getResources().getStringArray(fragmentClassNameResourceId);

    if(fragmentList.length != displayNameList.length) {
        Log.e("SetupTabbedNavigation",
                "ERROR - List of fragment class names and list of display names do not contain the same number of entries");
        return ;
    }

    ActionBar actionBar = containingActivity.getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    ActionBar.TabListener tablistener;
    for (int i=0; i < fragmentList.length; i++) {
        tablistener = new SimpleTabListener(containingActivity, fragmentList[i], viewGroupId);
        actionBar.addTab(
                actionBar.newTab()
                        .setText(displayNameList[i])
                        .setTabListener(tablistener)
        );
    }
}