Can We Nested Two Child Fragment Inside One Parent Fragment In View Pager?
I have a view pager,in one of tab I have parent fragment which contained two child fragment. Candidatelist is the parent fragment which had a frame container I replace one child(c
Solution 1:
I have resolved the issued on the second child fragment I used getFragmentManager
CandidateStartEventchildFragment=newCandidateStartEvent();
FragmentTransactiontransaction=getFragmentManager().beginTransaction();
transaction.replace(R.id.childContainer, childFragment).addToBackStack(null).commit();
Solution 2:
You can add child fragment in Parent fragment here i am replace fragment using spinner selection. 1) reports_main_segment.xml 2) ReportFragment .java (Parent fragment)
I have two child fragment like
1) LeadsReportFragment 2) OccupancyFragment
1) reports_main_segment.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:background="@color/gini_white_color"android:orientation="vertical"><Spinnerandroid:id="@+id/report_spinner"android:layout_width="fill_parent"android:layout_height="wrap_content"android:layout_margin="@dimen/_10sdp"android:background="@drawable/gray_border_edittext"android:dropDownVerticalOffset="80dp"android:entries="@array/reports_status"android:padding="@dimen/_5sdp"android:textColor="@color/gini_gray_color_b7b7b7"/><LinearLayoutandroid:id="@+id/child_fragment_view"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"></LinearLayout></LinearLayout>
2) ReportFragment.java
publicclassReportFragmentextendsFragment {
private ViewGroup root;
private Spinner report_spinner;
@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
root = (ViewGroup) inflater.inflate(R.layout.reports_main_segment,
null);
return root;
}
@OverridepublicvoidonResume() {
super.onResume();
FindViewById();
}
privatevoidFindViewById() {
report_spinner = (Spinner) root.findViewById(R.id.report_spinner);
report_spinner.setOnItemSelectedListener(newAdapterView.OnItemSelectedListener() {
@OverridepublicvoidonItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
Stringselected= adapterView.getItemAtPosition(i).toString();
if (selected.equalsIgnoreCase("Leads")) {
setFragment(1);
} elseif (selected.equalsIgnoreCase("Occupancy")) {
setFragment(2);
}
}
@OverridepublicvoidonNothingSelected(AdapterView<?> adapterView) {
// ToDo nothing selection
}
});
}
publicvoidsetFragment(int type) {
FragmentManagerfragmentManager= getFragmentManager();
FragmentTransactionfragmentTransaction= fragmentManager.beginTransaction();
if (type == 1) {
LeadsReportFragmentfragment=newLeadsReportFragment();
fragmentTransaction.replace(R.id.child_fragment_view, fragment);
} elseif (type == 2) {
OccupancyFragmentfragment=newOccupancyFragment();
fragmentTransaction.replace(R.id.child_fragment_view, fragment);
}
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
}
}
Post a Comment for "Can We Nested Two Child Fragment Inside One Parent Fragment In View Pager?"