Search code examples
androidandroid-fragmentstabsfragment-tab-host

Navigation with the Fragment tab host in android


I am currently work on a simple app that based on the fragment tabhost , the structure is like that:

3 tabs total

  1. About company
  2. Recent News
  3. Discuss board

And for example, at the Tab 1 (About company), there is an button call "Company policy", when I click on it , I currently use the CompanyPolicyActivity to implement it.

That means when I open it, I create a new Activity on top of the fragment Activity.

However, the tab bar is missing if I use Activity, I wonder are there any way to keep the tabhost bar at new activity / what is the standard way to implement that case e.g. replace fragment? (but it seems complex as I need to also handle the switch tab case, eg. return to first fragment when I switch page)

Thanks for helping

tabHost = (FragmentTabHost)findViewById(android.R.id.tabhost);
        tabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);

        tabHost.addTab(tabHost.newTabSpec("main").setIndicator(""),Home.class, null);
        tabHost.addTab(tabHost.newTabSpec("assistant").setIndicator("",getResources().getDrawable(R.drawable.btn_assistant)), Shop.class,null); //not clickable right now
        tabHost.addTab(tabHost.newTabSpec("coupon").setIndicator("",getResources().getDrawable(R.drawable.btn_coupon)), Coupon.class,null);
        tabHost.addTab(tabHost.newTabSpec("shop").setIndicator("",getResources().getDrawable(R.drawable.btn_shop)), Shop.class,null);

Solution

  • try to using getChildFragmentManager()