Back to project page android-mvc-framework.
The source code is released under:
Apache License
If you think the Android project android-mvc-framework listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.android_mvc.framework.ui.tab; // ww w.j a v a2s .c om import java.util.ArrayList; import com.android_mvc.framework.common.FWUtil; import com.android_mvc.framework.controller.routing.TabContentMapping; import android.app.Activity; import android.app.TabActivity; import android.content.Intent; import android.widget.TabHost; import android.widget.TabHost.TabSpec; /** * XML?????????????????????????????????????????????????????? * @author id:language_and_engineering * */ public class TabHostBuilder { // NOTE: ???????????Activity????????????? private TabActivity activity; private TabHost tabhost; private TabContentMapping map; private ArrayList<TabDescription> descriptions = new ArrayList<TabDescription>(); /** * ????? */ public TabHostBuilder(Activity context) { this.activity = (TabActivity)context; this.tabhost = activity.getTabHost(); } /** * ???????????????????????????????????????????????????????????????? */ public TabHostBuilder setChildActivities(TabContentMapping map) { this.map = map; return this; } /** * ???????????????????? * ????????????????????????? */ public TabHostBuilder add(TabDescription... descs) { for( int i = 0; i < descs.length; i ++ ) { this.descriptions.add(descs[i]); } return this; } /** * ?????????????????????????????????????????????????? */ public void display() { // ????Host????? for( int i = 0; i < descriptions.size(); i ++ ) { registerOneTabSpec( descriptions.get(i) ); } } /** * ?????????????????????????????????????????????????????? */ private void registerOneTabSpec(TabDescription desc) { // ????????? String tabTag = desc.tabTag; String displayText = desc.displayText; int icon_resource_id = desc.icon_resource_id; // 1???????????????? Class<? extends Activity> target_activity_class = map.getByTag(tabTag); if( target_activity_class == null ) { FWUtil.e( "???????????????????????????????????????" + tabTag + "???????????Activity??????????????????????????????????" ); return; } // spec????????????? TabSpec tabspec = tabhost .newTabSpec( tabTag ) .setContent( new Intent(activity, target_activity_class) .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) ) ; // ??????????????????????? if( icon_resource_id != 0 ) { tabspec.setIndicator(displayText, activity.getResources().getDrawable( icon_resource_id )); } else { tabspec.setIndicator(displayText); } // ??????????????? tabhost.addTab( tabspec ); } }