I have one main activity which is fragment activity here I am setting two tabs with two fragments A and B in the B fragment I have one button when the user click on the button I want to change fragment B to fragment C. But the tabs above are visible...
How I can achieve replacing fragments inside tabs?
Any solution are greatly appreciated.
Basic concept- We can achieve this by creating a container. Each tab will be assigned with a specific container. Now when we need a new fragment then we will replace same using this container.
Kindly follow undermentioned code step by step to have better understanding. Step-1: Create Tabs for your app. Say "Home.java". It will contain code for creating tabs using fragment.
Your home.xml file
Step-2: Define Base container fragment which will be helpful for backtracking and replacment of fragments "check out replaceFragement() ". Our class "BaseContainerFragment.java"
Step3: Now here I am considering for one fragment only hoping that rest can be handled by you in same fashion. Defining container Fragment class. Each tab will have specific container. Say TalkContainerFragment.java for first tab
It's xml file. "container_fragment.xml" this xml container contains frameLayout. we will use this id to replace different Fragments.
Your main class. "Talk.java"
That's it. You are good to go. The whole magic lies in calling R.id. instead of R.layout. Cheers!