在android中单击选项卡时启动主活动

时间:2012-08-23 10:54:41

标签: android

我有三个包含子活动的TAB,问题是当我点击任何一个TAB时它不显示主要活动..如何在三个TAB栏中显示主要活动...任何人都有解决方案为此。?

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);
}

2 个答案:

答案 0 :(得分:0)

我并不完全清楚你的观点,而是使用OnTabListener 开始意图..

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

答案 1 :(得分:0)

您可以在第一个tabspec中设置它,如下所示

  Intent HomeIntent = new Intent(this, MainClass.class);
  HomeSpec.setContent(HomeIntent);