1

For example, I have 5 tab inside a fragment tabhost.

For my past experience, if I have to implement a "go to detail" page inside a tab, I would just simply use activity to do (e.g. intent and create new activity).

Since I would like to keep the tabhost bar at the page so I can not use activity anymore , I need to change the fragment which is inside the tabhost. I tried using fragment transaction but when I switch tab the text is overlap, so how to change the fragment inside the tab? Thanks a lot.

This is how I create tabhost

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

tabHost.addTab(
        tabHost.newTabSpec("home").setIndicator("",
                getResources().getDrawable(R.drawable.btn_home)),
        HomeFragment.class, null);
tabHost.addTab(
        tabHost.newTabSpec("exhibit").setIndicator("",
                getResources().getDrawable(R.drawable.btn_exhibit)),
        ExhibitFragment.class, null);
tabHost.addTab(
        tabHost.newTabSpec("plan").setIndicator("",
                getResources().getDrawable(R.drawable.btn_floor_plan)),
        PlanFragment.class, null);
tabHost.addTab(
        tabHost.newTabSpec("collection").setIndicator("",
                getResources().getDrawable(R.drawable.btn_collection)),
        CollectionFragment.class, null);
tabHost.addTab(
        tabHost.newTabSpec("setting").setIndicator("",
                getResources().getDrawable(R.drawable.btn_setting)),
        SettingFragment.class, null);

This is how I go to detail before, I would like to use fragment now

private OnClickListener set_listener(final int pos) {
        OnClickListener listener = new OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(ctx, CollectionDetail.class);
                intent.putExtra("pos", pos);
                startActivity(intent);
            }
        };
        return listener;
    }
user3538235
  • 1,771
  • 5
  • 21
  • 46
  • 1
    What happens when you click on a tab with your current code? Only adding the tabs passing the fragments as arguments (as your first piece of code) should be necessary to navigate through the fragments using tabhost. No need for ClickListeners or implementing fragment transactions. See http://developer.android.com/reference/android/support/v4/app/FragmentTabHost.html and http://maxalley.wordpress.com/2013/05/18/android-creating-a-tab-layout-with-fragmenttabhost-and-fragments/ (Please let me know if I misunderstood the question) – Rodrigo Borges Nov 05 '14 at 03:28
  • Thanks. I found the answer here : http://stackoverflow.com/questions/18120510/dynamically-changing-the-fragments-inside-a-fragment-tab-host – user3538235 Nov 06 '14 at 01:27

0 Answers0