I have two fragments on top of each other when I call the second fragment I still the buttons from the first fragment stay visible and functional.
I tried many many methods but didn't work
This one gave me this error:
java.lang.IllegalArgumentException: No view found for id 0x7f0e0004 (*.test:id/customId) for fragment SecondFragment{adef947 #0 id=0x7f0e0004}
and This
java.lang.IllegalArgumentException: No view found for id 0x7f0e00ae (sy.aya.ayaisp.test:id/gatesViewpager) for fragment SecondSFragment{adef947 #0 id=0x7f0e00ae}
my code is as follows:
FirstFragment.java
public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstanceState) {
View myView = inflater.inflate(R.layout.first_fragment, container, false);
Button FBtn = (Button) myView.findViewById(R.id.Fbutton);
FBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Bundle bundle = new Bundle();
bundle.putString("second", "f button");
SecondFragment secondFragment = new secondFragment();
secondFragment.setArguments(bundle);
FragmentTransaction ft = getChildFragmentManager().beginTransaction();
ft.setCustomAnimations(R.anim.slide_in_up, R.anim.slide_in_up);
ft.replace(R.id.s_con, secondFragment).addToBackStack("back").commit();
}
});
SecondFrag.java
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
String bundleString = this.getArguments().getString("second");
View view = inflater.inflate(R.layout.s_rv, container, false);
RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.s_recyclerview);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
if (bundleString == "agents button") {
recyclerView.setAdapter(new SecondAdapter(getContext()));
}
}
first_fragment.xml
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/s_con"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="#+id/Fbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="secondFragment"/>
</android.support.constraint.ConstraintLayout>
s_rv.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<sy.aya.ayaisp.ExpandableRecyclerView
android:id="#+id/s_recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="5dp"
android:clipToPadding="false"
android:scrollbars="vertical" />
</FrameLayout>
Thank you for your help
In second fragment layout "s_rv" in root element of xml add some background, clickable="true" and focusable="true".
And in first fragment layout wrap your button in LinearLayout. two days back I was also facing same issue it was solved after that.
It is because in your first fragment the id of button is "pos_agents_button" but in findViewById you are trying to find "R.id.Fbutton".
Change
Button FBtn = (Button) myView.findViewById(R.id.Fbutton);
to
Button FBtn = (Button) myView.findViewById(R.id.pos_agents_button);
and everything should work fine.
Related
this is the code of dashboard page where when i click the list item ..it will overlap one fragment with other ..iam using navigation drawer activity
In this listview is overlap with recycler view i am sharing one image file also
this is problem in my app of overlapping
android
public class DashboardFragment extends Fragment {
FragmentManager mFragmentManager;
FragmentTransaction mFragmentTransaction;
ListView simpleList;
TextView textView;
String List[] = {"RELIGION", "CASTE", "SUBCASTE"};
public View onCreateView(#NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_dashboard, container, false);
simpleList=root.findViewById(R.id.simplelist);
textView=root.findViewById(R.id.item);
mFragmentManager = getActivity().getSupportFragmentManager();
mFragmentTransaction = mFragmentManager.beginTransaction();
ArrayAdapter adapter = new ArrayAdapter(getActivity(),R.layout.list_item_lisview,R.id.item, List);
simpleList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
adapter.getItem(position);
if(position==0)
{
if (savedInstanceState == null) {
FragmentTransaction fragmentTransaction = getActivity().getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(android.R.id.content, new ReligionFragment()).commit();
}
}
else
if(position==1) {
loadFragment(new CasteFragment());
}
else if(position==2) {
loadFragment(new SubCasteFragment());
}
}
});
simpleList.setAdapter(adapter);
return root;
}
public void loadFragment(Fragment fragment) {
FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction();
transaction.replace(android.R.id.content, fragment);
transaction.commit();
}
}
I have used Navigation Component for navigating among fragments which is pretty common in Android now a days. You would have seen navigation folder is created when you create a new Navigation Drawer Activity or Bottom Navigation Activity in updated android studio versions. Let's look one by one. First things first:
DashboardFragment.java
public class DashboardFragment extends Fragment {
public View onCreateView(#NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_dashboard, container, false);
}
}
fragment_dashboard.xml
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.dashboard.DashboardFragment">
<fragment
android:id="#+id/nav_host_dashboard_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navGraph="#navigation/dashboard_navigation" />
</androidx.constraintlayout.widget.ConstraintLayout>
Now create a file having name dashboard_navigation inside your navigation folder.
dashboard_navigation.xml
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/dashboard_navigation"
app:startDestination="#id/listFragment">
<fragment
android:id="#+id/listFragment"
android:name="com.pagingdemo.ui.dashboard.ListFragment"
android:label="fragment_list"
tools:layout="#layout/fragment_list" >
<action
android:id="#+id/action_listFragment_to_religionFragment"
app:destination="#id/religionFragment" />
<action
android:id="#+id/action_listFragment_to_casteFragment"
app:destination="#id/casteFragment" />
<action
android:id="#+id/action_listFragment_to_subCasteFragment"
app:destination="#id/subCasteFragment" />
</fragment>
<fragment
android:id="#+id/religionFragment"
android:name="com.pagingdemo.ui.dashboard.ReligionFragment"
android:label="fragment_religion"
tools:layout="#layout/fragment_religion" />
<fragment
android:id="#+id/casteFragment"
android:name="com.pagingdemo.ui.dashboard.CasteFragment"
android:label="fragment_caste"
tools:layout="#layout/fragment_caste" />
<fragment
android:id="#+id/subCasteFragment"
android:name="com.pagingdemo.ui.dashboard.SubCasteFragment"
android:label="fragment_sub_caste"
tools:layout="#layout/fragment_sub_caste" />
I have just created 4 fragments. 1st, ListFragment to show Religion, Caste and Sub Caste List. 2nd, ReligionFragment for religion recycler view. 3rd, CasteFragment for caste recycler view. 4th, SubCasteFragment for sub caste recycler view.
See my package name is different from your package name. So if you are copying code then please make sure you have created 4 fragments with correct name then replace in this navigation xml file.
I am just posting onCreateView() code of each of the above mentioned 4 fragments.
ListFragment's onCreateView looks like :
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
String[] list = {"RELIGION", "CASTE", "SUBCASTE"};
View rootView = inflater.inflate(R.layout.fragment_list, container, false);
final ListView simpleList = rootView.findViewById(R.id.list_dashboard);
ArrayAdapter adapter = new ArrayAdapter(getActivity(),R.layout.list_item_view,R.id.list_item_text_view, list);
simpleList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
switch (position){
case 0 : {
Navigation.findNavController(rootView).navigate(R.id.religionFragment);
break;
}
case 1 : {
Navigation.findNavController(rootView).navigate(R.id.casteFragment);
break;
}
case 2 : {
Navigation.findNavController(rootView).navigate(R.id.subCasteFragment);
break;
}
}
}
});
simpleList.setAdapter(adapter);
return rootView;
}
ListFragment's layout i.e fragment_list.xml looks like :
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".ui.dashboard.ListFragment">
<ListView
android:id="#+id/list_dashboard"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
ReligionFragment's onCreateView looks like :
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
ArrayList<String> religionList = new ArrayList();
religionList.add("Hindu");
religionList.add("Islam");
religionList.add("Christianity");
religionList.add("Budhisism");
religionList.add("Jainisism");
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_religion, container, false);
RecyclerView recyclerView = view.findViewById(R.id.religion_list_view);
recyclerView.setAdapter(new MyRecyclerAdapter(religionList));
return view;
}
Like wise you could use other two fragments such as CasteFragment and SubCasteFragment along with RecyclerView.
Please set android:background="#color/white" in your XML's Parent widget. it works for me because always fragment set default color transparent.
I am now practicing on ViewPager and Fragments but I am facing an issue with replacing fragment to one another.
It is working well with swiping screen to move to another fragment, but I also wanted to try out if I can do this with a button too.
So I added a button, and tried to use FragmentManager's replace() method.
But what it actually does is not replacing the fragment but adding the fragment on the current fragment.
In a simple word, it overlaps.
Could not really find anything helpful for hours now, can anyone please help me with it?
Here is my code of the fragment that has the button:
public class MainActivity extends Fragment {
Fragment fragment;
FragmentManager fragmentManager;
FragmentTransaction fragmentTransaction;
Button buildButton;
private ViewPager viewPager;
public static Fragment newInstance(Context context) {
MainActivity mainActivity = new MainActivity();
return mainActivity;
}
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, Bundle savedInstanceState) {
ViewGroup root = (ViewGroup) inflater.inflate(R.layout.main, null);
return root;
}
#Override
public void onActivityCreated(#Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
buildButton = (Button) getView().findViewById(R.id.buildButton);
buildButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
fragment = new SecondActivity();
fragmentManager = getActivity().getSupportFragmentManager();
fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.calendarActivity, fragment);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
}
});
}
}
And this is the xml file of the fragment:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<fragment class="com.example.auclo.calendarpractice5.MainActivity"
android:id="#+id/calendarActivity"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<Button
android:id="#+id/buildButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="100dp"
android:layout_marginEnd="148dp"
android:layout_marginStart="148dp"
android:layout_marginTop="16dp"
android:text="Track"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/calendarView" />
</android.support.constraint.ConstraintLayout>
And this is the fragment that I want to replace to:
public class SecondActivity extends Fragment {
TextView textView;
public static Fragment newInstance(Context context) {
SecondActivity secondActivity = new SecondActivity();
return secondActivity;
}
#Nullable
#Override
public View onCreateView(#NonNull LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
ViewGroup root = (ViewGroup) inflater.inflate(R.layout.activity_second, null);
return root;
}
#Override
public void onActivityCreated(#Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
textView = getView().findViewById(R.id.textView);
}
}
And xml of the second fragment:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SecondActivity">
<fragment class="com.example.auclo.calendarpractice5.SecondActivity"
android:id="#+id/secondActivity"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pikachu"
android:textSize="18sp" />
</RelativeLayout>
I will really appreciate to any kind of help.
Thank you!
The issue is that you're replacing the element with ID calendarActivity with your new fragment. This element is inside the XML for your first fragment (I think, based on your post). So it's putting this fragment in your old fragment.
You'll need to instead use the id in R.layout.main that represents your first fragment. I usually use a framelayout for this. Then I have the activity replace that framelayout with a fragment in its onCreate().
To add the same visual effects, you have to add a animation to your fragmentTransaction
Exemple:
fragmentTransaction.setCuston(
R.anim.enter_from_right,
R.anim.exit_to_left);
See this answer for explanation on fragments animations
Yesterday, I came across a problem that concerns "propably" fragments overlapping. I have a fragment (A) with RecyclerView & FloatingActionButton. There is onClickListener set to that FAB, which should replace the whole fragment (A) view with fragment (B). Unfortunately FAB somehow stays on top, but RecyclerView is exchanged with fragment (B) view. I'm almost sure that I'm replacing container with both RV & FAB. Maybe any ideas where should I look for solution?
Navigation code:
private void onNavigate(int container,Fragment fragment, boolean backStack, Integer animIn, Integer animOut){
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.addOnBackStackChangedListener(this);
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.setCustomAnimations(animIn,animOut,animIn,animOut);
fragmentTransaction.replace(container,fragment);
if(backStack){
fragmentTransaction.addToBackStack(fragment.toString());
}
fragmentTransaction.commit();
}
Fragment Replacing:
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState){
View view = inflater.inflate(R.layout.tab1_fragment, container, false);
recyclerView = (RecyclerView)view.findViewById(R.id.recyclerView_id);
FB_addTask = view.findViewById(R.id.fb_addTask_id);
recyclerView.setLayoutManager(new LinearLayoutManager(this.getActivity()));
FB_addTask.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
getNavigationListener().onNagivate(R.id.tab1_content,new Tab1_AddTask_Fragment(),true,R.anim.anim_from_left_to_right,R.anim.anim_from_center_to_left);
}
});
return view;
}
and Layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/tab1_content"
android:background="#color/Grey_300"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView_id"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
<android.support.design.widget.FloatingActionButton
android:id="#+id/fb_addTask_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_margin="25dp"
android:elevation="5dp"
android:src="#drawable/plus_dark_blue"
app:backgroundTint="#color/SC_Gold"/>
</RelativeLayout>
I want to call a fragment on button click which is a fragment. I tried this code but it's not working. with this code when I click on the button it shows next fragment but not its designing. I see only a blank page.
This is my main xml :-
<LinearLayout
android:id="#+id/main_layout"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<!-- our toolbar -->
<!-- our tablayout to display tabs -->
<android.support.design.widget.TabLayout
android:id="#+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="scrollable"
app:tabGravity="fill"
android:background="#fa4022"
android:minHeight="?attr/actionBarSize"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"/>
<!-- View pager to swipe views -->
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="fill_parent"/>
I have an dashboard tab in this TabLayout. In this dashboard tab i have an button which id is userprofile. after click on this button i want to go on user_profile.xml
public class Dashboard extends Fragment implements View.OnClickListener {
Button userprofile;
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.dashboard, container, false);
userprofile=(Button)rootView.findViewById(R.id.userprofile);
userprofile.setOnClickListener(this);
return rootView;
}
#Override
public void onClick(View view) {
Fragment fragment = null;
switch (view.getId()) {
case R.id.userprofile:
fragment = new User_Profile();
replaceFragment(fragment);
break;
}
}
private void replaceFragment(Fragment fragment) {
User_Profile user_profile = new User_Profile();
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(R.id.pager, fragment);
transaction.addToBackStack(null);
transaction.commit();
}
User_Profile class code is :-
public class User_Profile extends Fragment {
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View rooView=inflater.inflate(R.layout.user_profile, container, false);
return rooView;
}
}
user_profile.xml is :-
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="User Profile"
android:textSize="30dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"/>
If you can see fragment on button click but not designing then its may error in your fragment .xml file. By using proper view problem can be solve. If there is also a problem with same post their .xml file code.
Can you show us some more data please? What's the XML for the pager fragment you're trying to replace the current fragment with?
Could you check that you're referring to the layout of that XML file, and not the individual pager element too?
(Since transaction.replace requires a fragment container as it's first argument)
I'm trying to put 2 fragments inside a fragment. I found some code on internet but, as far as I could go, I don't succeed to put 2 fragments in 1 fragment.
I have seen tips dealing with FragmentManager and especially the method getChildFragmentManager() but I don't know how it works with 2 fragments.
For the story, I'm using an activity with ActionBar which creates 3 fragments. In one of them, I need to handle a graph and a kind of menu to change the graph scale. In this way, I need 2 fragments in one fragment.
Here is the code :
The fragment which handles the others:
public class GraphDisplayFragment extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View myFragmentView = inflater.inflate(R.layout.graph_fragment, container, false);
return myFragmentView;
}
}
The code to draw the graph:
public class GraphFragment extends Fragment {
private static final int SERIES_NR = 1;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
GraphicalView myFragmentView = ChartFactory.getTimeChartView(this.getActivity(), getDateDemoDataset(), getDemoRenderer(),null);
return myFragmentView;
}
//some functions to set graph propreties
}
The XML files :
graph_fragment.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<fragment
android:id="#+id/graph_fragment"
android:name="com.test.GraphFragment"
android:layout_width="match_parent"
android:layout_height="259dp" >
</fragment>
<fragment
android:name="com.test.GraphDetailFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/graph_detail_fragment">
</fragment>
</LinearLayout>
graph_detail.xml with a test implementation
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="211dp"
android:layout_height="wrap_content"
android:text="TextView" />
</LinearLayout>
The weird thing is, it works at the begining when I switch between fragments in the ActionBar but after 3-4 moves, I get this error :
android.view.InflateException: Binary XML file line #7: Error inflating class fragment
If anyone has the solution, it would be awesome!
So first off change your xml for graph_fragment.xml to this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<FrameLayout
android:id="#+id/graph_fragment_holder"
android:layout_width="match_parent"
android:layout_height="259dp" >
</FrameLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/graph_detail_fragment_holder">
</FrameLayout>
</LinearLayout>
Then in code to inflate them from the fragment use something like this
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.graph_fragment,
container, false);
FirstChildFragment frag1 = (FirstChildFragment) getChildFragmentManager()
.findFragmentById(R.id.first_frag_layout);
SecondChildFragment frag1 = (SecondChildFragment) getChildFragmentManager()
.findFragmentById(R.id.second_frag_layout);
if (null == frag1) {
FirstChildFragment = new frag1();
FragmentTransaction transaction = getChildFragmentManager()
.beginTransaction();
transaction.add(R.id.graph_fragment_holder, frag1)
.addToBackStack(null).commit();
}
if (null == frag2) {
SecondChildFragment = new frag2();
FragmentTransaction transaction = getChildFragmentManager()
.beginTransaction();
transaction.add(R.id.graph_detail_fragment_holder, frag2)
.addToBackStack(null).commit();
}
return rootView;
}
MyFragment myFragment = (MyFragment)getChildFragmentManager().findFragmentById(R.id.my_fragment);
You can try to use the method *findFragmentById(fragment_id)* from SupportFragmentManager to get the instance of fragment from your .xml file and insert your fragment there.
Something like:
Fragment myFragment = getSupportFragmentManager().findFragmentById(R.id.myFragmentId);
I hope to help you.
Best regards.
Adriano