I want to replace fragment to another fragment which contain by TabLayout Viewpager. like this:
Activity -> A Fragment -> B Fragment(TabLayout ViewPager) -> C Fragment(Tab's Fragment) -> D Fragment
I task is switch Fragment C to Fragment D.
Note:- TabLayout ViewPager also contain 3 tab Fragment control by FragmentPagerAdapter
.
Tablayout fragment's layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<android.support.design.widget.TabLayout
android:id="@+id/tablayout_postpaid_service"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
app:tabGravity="fill"
app:tabIndicatorColor="@color/white"
app:tabMode="scrollable"
app:tabSelectedTextColor="@color/white"
app:tabTextColor="@color/tab_fade_text_color" >
</android.support.design.widget.TabLayout>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager_postpaid_service"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- <FrameLayout
android:id="@+id/container_body"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" /> -->
</android.support.v4.view.ViewPager>
Fragment B class:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_select_postpaid_service, container, false);
tablayout = (TabLayout) view.findViewById(R.id.tablayout_postpaid_service);
viewpager = (ViewPager) view.findViewById(R.id.viewpager_postpaid_service);
viewpager.setAdapter(new TabPagerAdapter(getChildFragmentManager(), TabConstants.POSTPAID_SERVICE_TYPE_TABS_FLAG, TabConstants.POSTPAID_SERVICE_TYPE_TABS));
tablayout.post(new Runnable() {
@Override
public void run() {
tablayout.setupWithViewPager(viewpager);
setupTabIcons();
}
});
return view;
}
Fragment C class:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_select_operator, container,
false);
setGridview();
return view;
}
private void setGridview() {
operatorName = new ArrayList<String>();
operatorCode = new ArrayList<String>();
recyclerview = (RecyclerView) view
.findViewById(R.id.select_operator_recycler_view);
recyclerview.setHasFixedSize(true);
GridLayoutManager layoutManager = new GridLayoutManager(getActivity(),
Constants.NO_OF_OPERATOR_GRID);
recyclerview.setLayoutManager(layoutManager);
OperatorGridAdapter adapter = new OperatorGridAdapter(getActivity(),
HomeConstants.OPERATOR_LIST_ICON);
recyclerview.setAdapter(adapter);
recyclerview.addOnItemTouchListener(new RecyclerItemClickListener(
getActivity(),
new RecyclerItemClickListener.OnItemClickListener() {
@Override
public void onItemClick(View view, int position) {
navigateFragment(position);
}
}));
}
private void navigateFragment(int position) {
Fragment fragment = new DFragment();
// FragmentTransaction fragmentTransaction = getChildFragmentManager().beginTransaction();
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.container_body, fragment);
//fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
((AppCompatActivity) getActivity()).getSupportActionBar().setTitle(
getResources().getString(R.string.app_name));
Log.d(Constants.ACTIVITY_TAG, "********************");
}
I getting an error
java.lang.IllegalArgumentException: No view found for id 0x7f0a006e (com.recharge:id/container_body) for fragment DFragment{4327cfd0 #2 id=0x7f0a006e}
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1070)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1259)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1624)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:517)
I've tried many tick and solution but not hit for me .
Please help me short out this problem.