2013-05-14 5 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를 재정렬하여 초기에 다섯 번째 탭을 시작합니다 .... – khurramengr

답변

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)

+1

문제는 탭을 변경하지 않는다는 것입니다. 실제로 탭을 변경하지만 처음에는 첫 번째 탭을 시작합니다. 스레드를 시작한 다음 5 번째 탭으로 전환하면 첫 번째 탭으로 이동하지 않고 5 번째 탭으로 직접 이동하려고합니다. – khurramengr

+0

초기 시간에 tabhost의 모든 활동의 수명을 알아야합니다. 실제로 초기 시간에 setCurrentTab (5)를 사용할 때 첫 번째 활동의 onCreate를 실행합니다. 첫 번째 활동에서 onResume으로 스레드를 이동해야합니다. – Mejonzhan