2012-08-23 96 views
0

我有三個包含子活動的TAB,問題是當我點擊任何一個TAB時它不顯示主要活動..我如何顯示主活動在這些三個TAB欄...任何人都有解決方案。開始主要活動時,當標籤在android中被點擊

日Thnx提前.. :)

Tabmain TabActivity

TabHost tabHost = getTabHost(); 
    TabSpec HomeSpec = tabHost.newTabSpec("Home"); 
    HomeSpec.setIndicator("Home", getResources().getDrawable(R.drawable.home)); 
    Intent HomeIntent = new Intent(this, HomeMediator.class); 
    HomeSpec.setContent(HomeIntent); 

    TabSpec SearchSpec = tabHost.newTabSpec("Search"); 
    SearchSpec.setIndicator("Search", getResources().getDrawable(R.drawable.search)); 
    Intent songsIntent = new Intent(this, SearchMediator.class); 
    SearchSpec.setContent(songsIntent); 

    TabSpec TreeInfoSpac = tabHost.newTabSpec("Tree Info"); 
    TreeInfoSpac.setIndicator("Botanical Name", getResources().getDrawable(R.drawable.carrot)); 
    Intent videosIntent = new Intent(this, BotaniacalMediator.class); 
    TreeInfoSpac.setContent(videosIntent); 

    tabHost.addTab(HomeSpec); 
    tabHost.addTab(SearchSpec); 
    tabHost.addTab(TreeInfoSpac); 
    tabHost.setOnTabChangedListener(new OnTabChangeListener() { 

     @Override 
     public void onTabChanged(String tabId) { 
      // TODO Auto-generated method stub 

     } 
    }); 

TabGroupActivity;

private ArrayList<String> mIdList; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    if (mIdList == null) { 
     mIdList = new ArrayList<String>(); 

    } 
} 


public void finishFromChild(Activity child) { 
    LocalActivityManager manager = getLocalActivityManager(); 
    int index = mIdList.size() - 1; 

    if (index < 0) { 
     finish(); 
     return; 
    } 

    manager.destroyActivity(mIdList.get(index), true); 
    Log.i("Activity Finish:", manager.getCurrentId()); 
    mIdList.remove(index); 
    index--; 
    String lastId = mIdList.get(index); 
    Intent lastIntent = manager.getActivity(lastId).getIntent(); 
    Window newWindow = manager.startActivity(lastId, lastIntent); 
    setContentView(newWindow.getDecorView()); 
} 

public void startChildActivity(String Id, Intent intent) { 

    Window window = getLocalActivityManager().startActivity(Id, 
      intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)); 
    if (window != null) { 
     mIdList.add(Id); 
     setContentView(window.getDecorView()); 
     Log.i("Activity Start:", getLocalActivityManager().getCurrentId()); 
    } 
} 

HomeMediator

public void onCreate(Bundle savedInstanceState) { 
    // TODO Auto-generated method stub 
    group = this; 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.mediator); 
    Intent LoginIntent = new Intent(HomeMediator.this, home.class); 
    startChildActivity("Home", LoginIntent); 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.home); 
    parentActivity = (TabGroupActivity) getParent(); 
} 

public void btnInfo_Click(View v) { 
    Intent i = new Intent(getParent(), records.class); 
    i.putExtra("VAL", "BotanicalName"); 
    parentActivity.startChildActivity("Botanical", i); 
} 
+1

請提供您使用qtn的代碼有點模糊 –

回答

0

我並不確切地知道你的觀點,但使用OnTabListener 開始意圖..

Intent main = new Intent (yourclass.this, MainClass.class); 
startActivity(main); 
0

你可以將它設置爲如下所示的第一個tabspec

Intent HomeIntent = new Intent(this, MainClass.class); 
    HomeSpec.setContent(HomeIntent); 
相關問題