0

android TabActivity 在设置 tabhost.setCurretnTab(4) 之前启动与序列中添加的第一个选项卡关联的 FragmentActivity;

@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tab_main);
    try
    { 
        DataSource.ObjContext = this.getApplicationContext();
        DataSource.ObjTabBarActivity = this;
        DataSource.ObjSharedPreferences = this.getSharedPreferences("com.example", Context.MODE_PRIVATE);
        if(NetworkStat)
        {
            new LocationUpdates(this);

            this.setTabs();

        }
        else
        {
            Log.d("in TabBarActivity", "Network failure");
            Toast.makeText(this.getApplicationContext(), "Network failure", Toast.LENGTH_SHORT).show();
        }
    }
   catch(Exception ex)
    { 

    }


}

private void setTabs()
{
    addTab("Clubs", R.drawable.tab_clubs,  FragmentStackClubsActivity.class);
    addTab("Events", R.drawable.tab_events, FragmentStackEventsActivity.class);
    addTab("Rate", R.drawable.tab_rate, FragmentStackRateActivity.class);
    addTab("Loyalty", R.drawable.tab_loyalty, FragmentStackLoyaltyActivity.class);
    addTab("Setting", R.drawable.tab_settings, FragmentStackSettingsActivity.class);
    if(DataSource.ObjSharedPreferences.getString(DataSource.LOGIN_TAG, "false").equalsIgnoreCase("false"))
    {

        getTabHost().setCurrentTab(4);
        DataSource.disableTabBar();
    }
    else
    {

    }

}
private void addTab(String labelId, int drawableId, Class<?> c)
{
    TabHost tabHost = getTabHost();
    Intent intent = new Intent(this, c);
    TabHost.TabSpec spec = tabHost.newTabSpec("tab" + labelId); 

    View tabIndicator = LayoutInflater.from(this).inflate(R.layout.tab_indicator, getTabWidget(), false);
    TextView title = (TextView) tabIndicator.findViewById(R.id.title);
    title.setText(labelId);
    ImageView icon = (ImageView) tabIndicator.findViewById(R.id.icon);
    icon.setImageResource(drawableId);

    spec.setIndicator(tabIndicator);
    spec.setContent(intent);
    tabHost.addTab(spec);
}

但问题是它最初启动第一个选项卡,然后以这种方式切换到第 5 个选项卡,线程从第一个选项卡开始,这就是我不想要的,即如果用户未登录,我想将用户重定向到登录(设置)选项卡。非常感谢这方面的任何帮助......

4

1 回答 1

1
public void setCurrentTab (int index)
public void setCurrentTabByTag (String tag)

你可以喜欢这个

if (isNotLogin) {
     tabHost.setCurrentTabByTag("Setting");
}

在 addTab() 之后

http://developer.android.com/reference/android/widget/TabHost.html#setCurrentTab(int)

于 2013-05-14T11:22:48.287 回答