Reputation: 617
I'm using TabHost and I have a problem. What I want is first tab should be a FragmentActivity and it can switch to another Fragments. This application helps me but I have also questions. In this example, you can go to infinite another Fragments but it's happening by the help of launchNewFragment method and this method is called from xml. But I need to call this method programmatically because when button is clicked, I also want to move some values (such as selected values in dialog) to another Fragment. Or is there another way to solve this problem? I'm waiting your suggestions.
Upvotes: 2
Views: 5618
Reputation: 3150
You might want to use Action Bar with Tabs instead of TabHost. You can get information about how to use it here: http://developer.android.com/guide/topics/ui/actionbar.html#Tabs
No matter on the chosen solution, replacing the displayed fragment in an activity is done like this:
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(android.R.id.content, new MyFragment());
transaction.commit();
You just have to add this to the button listener and replace MyFragment with your fragment.
Upvotes: 1