如何从TabActivity中的Activity转到特定的Activity?

时间:2011-11-24 14:11:17

标签: android

我想从一个Activity,点击按钮到TabActivity中的特定Activity。 我怎么能这样做?

这是我的TabActivity:

public class CustomTab extends ActivityGroup {

    public static final String TAB_ID = null;
    private TabHost mTabHost;

    private void setupTabHost() {
        mTabHost = (TabHost) findViewById(android.R.id.tabhost);
        mTabHost.setup(this.getLocalActivityManager());
    }

    /** Called when the activity is first created. */

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // construct the tabhost
        setContentView(R.layout.custom_tab);

        setupTabHost();

        mTabHost.getTabWidget().setDividerDrawable(R.drawable.tab_divider);

        setupTab(new TextView(this), "HELFOMAT", (MainActivity.class));
        setupProjectTab(new TextView(this), "PROJEKTE", (ProjectTab.class));
        setupContactTab(new TextView(this), "KONTAKT", (ContactActivity.class));
        setupInfoTab(new TextView(this), "INFOS", (InfosActivity.class));
    }

    private void setupTab(final View view, final String tag, final Class<?> context) {
        View tabview = createTabView(mTabHost.getContext(), tag);

        TabSpec ts1 = mTabHost.newTabSpec("TAB_DATE"); 
        ts1.setIndicator(tabview); 
        ts1.setContent(new Intent(this,context)); 

        mTabHost.addTab(ts1);

    }

    private static View createTabView(final Context context, final String text) {
        View view = LayoutInflater.from(context).inflate(R.layout.tab_helfomat_bg, null);
        TextView tv = (TextView) view.findViewById(R.id.tabsText);
        tv.setText(text);
        return view;
    }

    private void setupContactTab(final View view, final String tag, final Class<?> context) {
        View tabview = createContactTabView(mTabHost.getContext(), tag);
        TabSpec ts1 = mTabHost.newTabSpec("TAB_DATE"); 
        ts1.setIndicator(tabview); 
        ts1.setContent(new Intent(this,context)); 

        mTabHost.addTab(ts1);

    }

    private static View createInfoView(final Context context, final String text) {
        View view = LayoutInflater.from(context).inflate(R.layout.tab_info_bg, null);
        TextView tv = (TextView) view.findViewById(R.id.tabsText);
        tv.setText(text);
        return view;
    }

    private void setupInfoTab(final View view, final String tag, final Class<?> context) {
        View tabview = createInfoView(mTabHost.getContext(), tag);
        TabSpec ts1 = mTabHost.newTabSpec("TAB_DATE"); 
        ts1.setIndicator(tabview); 
        ts1.setContent(new Intent(this,context)); 

        mTabHost.addTab(ts1);

    }

    private static View createContactTabView(final Context context, final String text) {
        View view = LayoutInflater.from(context).inflate(R.layout.tab_contact_bg, null);
        TextView tv = (TextView) view.findViewById(R.id.tabsText);
        tv.setText(text);
        return view;
    }

    private void setupProjectTab(final View view, final String tag, final Class<?> context) {
        View tabview = createProjectTabView(mTabHost.getContext(), tag);
        TabSpec ts1 = mTabHost.newTabSpec("TAB_DATE"); 
        ts1.setIndicator(tabview); 
        ts1.setContent(new Intent(this,context)); 

        mTabHost.addTab(ts1);

    }

    private static View createProjectTabView(final Context context, final String text) {
        View view = LayoutInflater.from(context).inflate(R.layout.tab_project_bg, null);
        TextView tv = (TextView) view.findViewById(R.id.tabsText);
        tv.setText(text);
        return view;
    }
}

1 个答案:

答案 0 :(得分:0)

mTabHost.setCurrentTab(tabnumber);应该做的伎俩