如何避免在一个TabActivity第一个选项卡开始活动

如何避免在一个TabActivity第一个选项卡开始活动

本文介绍了如何避免在一个TabActivity第一个选项卡开始活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想,以避免在第一个选项卡开始活动.. tabHost.setCurrentTab(1)。当选项卡活动开始,我预计,只有在选项卡活动得到启动。但是,目前,Android开始在选项卡1和活动都活动选项卡,如果我设置选项卡为默认当前标签

 进口android.app.TabActivity;
进口android.content.Intent;
进口android.content.res.Resources;
进口android.os.Bundle;
进口android.util.Log;
进口android.view.Window;
进口android.widget.TabHost;
进口android.widget.TabHost.TabSpec;@燮pressWarnings(德precation)公共类SAMPLE1扩展TabActivity {
    串postContent;    公共无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);        requestWindowFeature(Window.FEATURE_NO_TITLE);        的setContentView(R.layout.main2);
        束束= this.getIntent()getExtras()。
        postContent = bundle.getString(URL);
             Log.d(securl1,postContent);
        资源ressources = getResources();
        TabHost tabHost = getTabHost();        // Android的标签
        //苹果标签
        意图int​​entApple =新意图()setClass(这一点,AppleActivity.class)。
        intentApple.putExtra(URL,postContent);
        则tabspec tabSpecApple = tabHost
            .newTabSpec(苹果)
            .setIndicator(网络)
            .setContent(intentApple);        // Windows选项卡
        意图int​​entWindows =新意图()setClass(这一点,WindowsActivity.class)。
        则tabspec tabSpecWindows = tabHost
            .newTabSpec(视窗)
            .setIndicator(智能)
            .setContent(intentWindows);        //黑莓标签
        意图int​​entBerry =新意图()setClass(这一点,BlackBerryActivity.class)。
        intentBerry .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        则tabspec tabSpecBerry = tabHost
            .newTabSpec(贝里)
            .setIndicator(,ressources.getDrawable(R.drawable.ic_menu_share_holo_dark))
            .setContent(intentBerry);
        意图int​​entAndroid =新意图()setClass(这一点,AndroidActivity.class)。
        intentAndroid .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        则tabspec tabSpecAndroid = tabHost
            .newTabSpec(机器人)
            .setIndicator(,ressources.getDrawable(R.drawable.ic_menu_back))            .setContent(intentAndroid);
        意图int​​entBerry1 =新意图()setClass(这一点,BlackBerryActivity1.class)。
        则tabspec tabSpecBerry1 = tabHost
            .newTabSpec(贝里)
            .setIndicator(浆果)
            .setContent(intentBerry1);        //添加所有标签
        tabHost.addTab(tabSpecAndroid);
        tabHost.addTab(tabSpecApple);
        tabHost.addTab(tabSpecWindows);
        tabHost.addTab(tabSpecBerry);        // Windows设置选项卡,默认值(从零开始)
        tabHost.setCurrentTab(1);
    }}


解决方案

试试这个。

  mTab​​Host.getTabWidget()getChildAt(0).setEnabled(假);

希望这会为你工作。 :)

i want to avoid starting activity in the first tab .. tabHost.setCurrentTab(1). When the tab activity starts, I expect that only the activity in tab 2 gets started. But, currently, Android starts both activity in tab 1 and activity in tab 2, if I set tab 2 as default current tab

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. :)

这篇关于如何避免在一个TabActivity第一个选项卡开始活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 12:25