2013-05-14 83 views
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片這樣一個線程會從第一個標籤開始,而這正是我不想也就是說,如果用戶沒有登錄在我想重定向用戶登錄(設置)選項卡。 這方面的任何幫助,高度讚賞......

+0

我不想重新排列TabBar以便最初啓動第5個選項卡。 – khurramengr 2013-05-14 11:20:27

回答

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

你可以喜歡這個

​​

addTab()後

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

+1

問題不在於它不會更改選項卡,實際上它確實會更改選項卡,但會首先啓動第一個選項卡哪一個線程開始,然後切換到第5個選項卡,我想直接進入第5個選項卡,而不需要第一個選項卡 – khurramengr 2013-05-14 11:42:29

+0

您需要知道在初始時間tabhost中每個活動的生命週期;實際上,當您在初始時間使用setCurrentTab(5)時,它僅運行第一個活動的onCreate;所以你需要在第一個活動中將線程移動到onResume。 – Mejonzhan 2013-05-16 06:19:18