简体   繁体   English

如何避免在TabActivity的第一个选项卡上启动活动?

[英]How to avoid starting the activity at the first tab in a TabActivity?

i want to avoid starting activity in the first tab .. tabHost.setCurrentTab(1). 我想避免在第一个选项卡中开始活动.. tabHost.setCurrentTab(1)。 When the tab activity starts, I expect that only the activity in tab 2 gets started. 选项卡活动开始时,我希望只有选项卡2中的活动才能开始。 But, currently, Android starts both activity in tab 1 and activity in tab 2, if I set tab 2 as default current tab 但是,目前,如果我将标签2设置为默认当前标签,则Android会同时在标签1和2中启动活动

import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;

@SuppressWarnings("deprecation")

public class sample1 extends TabActivity {
    String postContent;

    public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_NO_TITLE);  

        setContentView(R.layout.main2);
        Bundle bundle = this.getIntent().getExtras();
        postContent = bundle.getString("url");
             Log.d("securl1",postContent);
        Resources ressources = getResources(); 
        TabHost tabHost = getTabHost(); 

        // Android tab


        // Apple tab
        Intent intentApple = new Intent().setClass(this, AppleActivity.class);
        intentApple.putExtra("url", postContent);
        TabSpec tabSpecApple = tabHost
            .newTabSpec("Apple")
            .setIndicator("Web")
            .setContent(intentApple);

        // Windows tab
        Intent intentWindows = new Intent().setClass(this, WindowsActivity.class);
        TabSpec tabSpecWindows = tabHost
            .newTabSpec("Windows")
            .setIndicator("Smart")
            .setContent(intentWindows);

        // Blackberry tab
        Intent intentBerry = new Intent().setClass(this, BlackBerryActivity.class);
        intentBerry .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        TabSpec tabSpecBerry = tabHost
            .newTabSpec("Berry")
            .setIndicator("", ressources.getDrawable(R.drawable.ic_menu_share_holo_dark))
            .setContent(intentBerry);


        Intent intentAndroid = new Intent().setClass(this, AndroidActivity.class);
        intentAndroid .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        TabSpec tabSpecAndroid = tabHost
            .newTabSpec("Android")
            .setIndicator("", ressources.getDrawable(R.drawable.ic_menu_back))

            .setContent(intentAndroid);


        Intent intentBerry1 = new Intent().setClass(this, BlackBerryActivity1.class);
        TabSpec tabSpecBerry1 = tabHost
            .newTabSpec("Berry")
            .setIndicator("berry")
            .setContent(intentBerry1);

        // add all tabs 
        tabHost.addTab(tabSpecAndroid);
        tabHost.addTab(tabSpecApple);
        tabHost.addTab(tabSpecWindows);
        tabHost.addTab(tabSpecBerry);

        //set Windows tab as default (zero based)
        tabHost.setCurrentTab(1);
    }

}

Try this. 尝试这个。

 mTabHost.getTabWidget().getChildAt(0).setEnabled(false);

hope it will work for you. 希望它对您有用。 :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何防止在TabActivity的第一个选项卡上启动活动? - How to prevent starting the activity at the first tab in a TabActivity? 触摸选项卡小部件时,TabActivity无法启动活动 - TabActivity not starting activity when tab widget touched 如何通过“活动”(标签)在TabActivity中设置控件的可见性? - How to setVisibility for control in TabActivity from Activity (tab)? 如何从tabactivity开始的活动中更改tabactivity的选项卡? 或更改当前选项卡 - how to change tab of a tabactivity from an activity started by the tabactivity ? or change current tab 从Activity类启动TabActivity - Starting TabActivity from Activity class 在TabActivity的单个选项卡中重新启动活动? - Restarting an activity in a single tab in a TabActivity? 如何从另一个活动中调用TabActivity getTabHost()? 避免NullPointerException - How to call TabActivity getTabHost() from another activity? to avoid NullPointerException 如何在TabActivity中搜索选项卡中的每个活动 - How can i searching in TabActivity for each activity in tab 如何在不让活动扩展TabActivity的情况下添加标签布局? - How to add tab layout without letting the activity to extend TabActivity? 单击tabActivity的选项卡以调用活动时如何调用函数 - How to Call a function when click a tab of tabActivity insted of call an Activity
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM