Reputation: 4080
I have a FragmentTabHost that contains 5 tabs. One of them loads a ListFragment. When an Item in the list is clicked I'd like to load a new fragment into the current tab. I can't seem to find out how to do this. The only thing I've managed to do is launch a whole new activity with the new content. How would I go about loading a new fragment into the active tab?
Upvotes: 2
Views: 3713
Reputation: 368
In the onClick method of your list you can call the method in the activity with the following code that replaces the fragment (supposing android.R.id.tabcontent is the id of FrameLayout in FragmentTabHost):
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(android.R.id.tabcontent, new TabFragment());
transaction.addToBackStack(null);
transaction.commit();
Upvotes: 5