How to change fragments within a view pager hosted by a Navigation Drawer










1















I have an Android app with a Navigation Drawer. When each drawer item is clicked, it displays two fragments hosted within a viewpager and tab layout.
I am unable to switch between the selected Navigation Drawer items as it is throwing an IllegalStateException.

I cannot figure out why as the content_main is hosting the layout.


Code for changing fragments:



FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.content_main, fragment);
ft.commit();




XML code for the app_bar_main.xml:



<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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/coordinator_main"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
tools:context=".activities.MainActivity">

<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay"

>

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar_main"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />

<android.support.design.widget.TabLayout
android:id="@+id/tab_layout_main"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
app:tabGravity="fill"
app:tabIndicatorColor="@color/colorAccent"
app:tabIndicatorHeight="3dp"
app:tabMode="fixed"
app:tabSelectedTextColor="@color/colorAccent"
app:tabTextColor="#FFFFFF" />

</android.support.design.widget.AppBarLayout>

<android.support.v4.view.ViewPager
android:id="@+id/viewpager_main"
android:layout_width="match_parent"
android:layout_height="match_parent"

android:layout_marginTop="108dp">

<include layout="@layout/content_main" />
</android.support.v4.view.ViewPager>






The XML code for the content_main.xml:



<FrameLayout 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/content_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".activities.MainActivity"
tools:showIn="@layout/app_bar_main">






A dump of the error message from LogCat:



2018-11-14 14:19:22.741 27690-27690/com.lomakuit.phwandoorganiser E/FragmentManager: No view found for id 0x7f08008a (com.lomakuit.phwandoorganiser:id/content_main) for fragment TicketCollectorsFragment570be2e #3 id=0x7f08008a
2018-11-14 14:19:22.741 27690-27690/com.lomakuit.phwandoorganiser E/FragmentManager: Activity state:
2018-11-14 14:19:22.788 27690-27690/com.lomakuit.phwandoorganiser E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.lomakuit.phwandoorganiser, PID: 27690
java.lang.IllegalArgumentException: No view found for id 0x7f08008a (com.lomakuit.phwandoorganiser:id/content_main) for fragment TicketCollectorsFragment570be2e #3 id=0x7f08008a
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1454)
at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852)
at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:802)
at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2625)
at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2411)
at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2366)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2273)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:733)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6944)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)





I'm unsure of how I can switch between fragments.

enter image description hereenter image description here










share|improve this question




























    1















    I have an Android app with a Navigation Drawer. When each drawer item is clicked, it displays two fragments hosted within a viewpager and tab layout.
    I am unable to switch between the selected Navigation Drawer items as it is throwing an IllegalStateException.

    I cannot figure out why as the content_main is hosting the layout.


    Code for changing fragments:



    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    ft.replace(R.id.content_main, fragment);
    ft.commit();




    XML code for the app_bar_main.xml:



    <?xml version="1.0" encoding="utf-8"?>
    <android.support.design.widget.CoordinatorLayout 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/coordinator_main"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#FFFFFF"
    tools:context=".activities.MainActivity">

    <android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay"

    >

    <android.support.v7.widget.Toolbar
    android:id="@+id/toolbar_main"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    app:popupTheme="@style/AppTheme.PopupOverlay" />

    <android.support.design.widget.TabLayout
    android:id="@+id/tab_layout_main"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/colorPrimary"
    app:tabGravity="fill"
    app:tabIndicatorColor="@color/colorAccent"
    app:tabIndicatorHeight="3dp"
    app:tabMode="fixed"
    app:tabSelectedTextColor="@color/colorAccent"
    app:tabTextColor="#FFFFFF" />

    </android.support.design.widget.AppBarLayout>

    <android.support.v4.view.ViewPager
    android:id="@+id/viewpager_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"

    android:layout_marginTop="108dp">

    <include layout="@layout/content_main" />
    </android.support.v4.view.ViewPager>






    The XML code for the content_main.xml:



    <FrameLayout 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/content_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context=".activities.MainActivity"
    tools:showIn="@layout/app_bar_main">






    A dump of the error message from LogCat:



    2018-11-14 14:19:22.741 27690-27690/com.lomakuit.phwandoorganiser E/FragmentManager: No view found for id 0x7f08008a (com.lomakuit.phwandoorganiser:id/content_main) for fragment TicketCollectorsFragment570be2e #3 id=0x7f08008a
    2018-11-14 14:19:22.741 27690-27690/com.lomakuit.phwandoorganiser E/FragmentManager: Activity state:
    2018-11-14 14:19:22.788 27690-27690/com.lomakuit.phwandoorganiser E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.lomakuit.phwandoorganiser, PID: 27690
    java.lang.IllegalArgumentException: No view found for id 0x7f08008a (com.lomakuit.phwandoorganiser:id/content_main) for fragment TicketCollectorsFragment570be2e #3 id=0x7f08008a
    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1454)
    at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784)
    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852)
    at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:802)
    at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2625)
    at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2411)
    at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2366)
    at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2273)
    at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:733)
    at android.os.Handler.handleCallback(Handler.java:789)
    at android.os.Handler.dispatchMessage(Handler.java:98)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6944)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)





    I'm unsure of how I can switch between fragments.

    enter image description hereenter image description here










    share|improve this question


























      1












      1








      1








      I have an Android app with a Navigation Drawer. When each drawer item is clicked, it displays two fragments hosted within a viewpager and tab layout.
      I am unable to switch between the selected Navigation Drawer items as it is throwing an IllegalStateException.

      I cannot figure out why as the content_main is hosting the layout.


      Code for changing fragments:



      FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
      ft.replace(R.id.content_main, fragment);
      ft.commit();




      XML code for the app_bar_main.xml:



      <?xml version="1.0" encoding="utf-8"?>
      <android.support.design.widget.CoordinatorLayout 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/coordinator_main"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:background="#FFFFFF"
      tools:context=".activities.MainActivity">

      <android.support.design.widget.AppBarLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:theme="@style/AppTheme.AppBarOverlay"

      >

      <android.support.v7.widget.Toolbar
      android:id="@+id/toolbar_main"
      android:layout_width="match_parent"
      android:layout_height="?attr/actionBarSize"
      android:background="?attr/colorPrimary"
      app:popupTheme="@style/AppTheme.PopupOverlay" />

      <android.support.design.widget.TabLayout
      android:id="@+id/tab_layout_main"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:background="@color/colorPrimary"
      app:tabGravity="fill"
      app:tabIndicatorColor="@color/colorAccent"
      app:tabIndicatorHeight="3dp"
      app:tabMode="fixed"
      app:tabSelectedTextColor="@color/colorAccent"
      app:tabTextColor="#FFFFFF" />

      </android.support.design.widget.AppBarLayout>

      <android.support.v4.view.ViewPager
      android:id="@+id/viewpager_main"
      android:layout_width="match_parent"
      android:layout_height="match_parent"

      android:layout_marginTop="108dp">

      <include layout="@layout/content_main" />
      </android.support.v4.view.ViewPager>






      The XML code for the content_main.xml:



      <FrameLayout 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/content_main"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      app:layout_behavior="@string/appbar_scrolling_view_behavior"
      tools:context=".activities.MainActivity"
      tools:showIn="@layout/app_bar_main">






      A dump of the error message from LogCat:



      2018-11-14 14:19:22.741 27690-27690/com.lomakuit.phwandoorganiser E/FragmentManager: No view found for id 0x7f08008a (com.lomakuit.phwandoorganiser:id/content_main) for fragment TicketCollectorsFragment570be2e #3 id=0x7f08008a
      2018-11-14 14:19:22.741 27690-27690/com.lomakuit.phwandoorganiser E/FragmentManager: Activity state:
      2018-11-14 14:19:22.788 27690-27690/com.lomakuit.phwandoorganiser E/AndroidRuntime: FATAL EXCEPTION: main
      Process: com.lomakuit.phwandoorganiser, PID: 27690
      java.lang.IllegalArgumentException: No view found for id 0x7f08008a (com.lomakuit.phwandoorganiser:id/content_main) for fragment TicketCollectorsFragment570be2e #3 id=0x7f08008a
      at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1454)
      at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784)
      at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852)
      at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:802)
      at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2625)
      at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2411)
      at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2366)
      at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2273)
      at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:733)
      at android.os.Handler.handleCallback(Handler.java:789)
      at android.os.Handler.dispatchMessage(Handler.java:98)
      at android.os.Looper.loop(Looper.java:164)
      at android.app.ActivityThread.main(ActivityThread.java:6944)
      at java.lang.reflect.Method.invoke(Native Method)
      at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)





      I'm unsure of how I can switch between fragments.

      enter image description hereenter image description here










      share|improve this question
















      I have an Android app with a Navigation Drawer. When each drawer item is clicked, it displays two fragments hosted within a viewpager and tab layout.
      I am unable to switch between the selected Navigation Drawer items as it is throwing an IllegalStateException.

      I cannot figure out why as the content_main is hosting the layout.


      Code for changing fragments:



      FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
      ft.replace(R.id.content_main, fragment);
      ft.commit();




      XML code for the app_bar_main.xml:



      <?xml version="1.0" encoding="utf-8"?>
      <android.support.design.widget.CoordinatorLayout 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/coordinator_main"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:background="#FFFFFF"
      tools:context=".activities.MainActivity">

      <android.support.design.widget.AppBarLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:theme="@style/AppTheme.AppBarOverlay"

      >

      <android.support.v7.widget.Toolbar
      android:id="@+id/toolbar_main"
      android:layout_width="match_parent"
      android:layout_height="?attr/actionBarSize"
      android:background="?attr/colorPrimary"
      app:popupTheme="@style/AppTheme.PopupOverlay" />

      <android.support.design.widget.TabLayout
      android:id="@+id/tab_layout_main"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:background="@color/colorPrimary"
      app:tabGravity="fill"
      app:tabIndicatorColor="@color/colorAccent"
      app:tabIndicatorHeight="3dp"
      app:tabMode="fixed"
      app:tabSelectedTextColor="@color/colorAccent"
      app:tabTextColor="#FFFFFF" />

      </android.support.design.widget.AppBarLayout>

      <android.support.v4.view.ViewPager
      android:id="@+id/viewpager_main"
      android:layout_width="match_parent"
      android:layout_height="match_parent"

      android:layout_marginTop="108dp">

      <include layout="@layout/content_main" />
      </android.support.v4.view.ViewPager>






      The XML code for the content_main.xml:



      <FrameLayout 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/content_main"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      app:layout_behavior="@string/appbar_scrolling_view_behavior"
      tools:context=".activities.MainActivity"
      tools:showIn="@layout/app_bar_main">






      A dump of the error message from LogCat:



      2018-11-14 14:19:22.741 27690-27690/com.lomakuit.phwandoorganiser E/FragmentManager: No view found for id 0x7f08008a (com.lomakuit.phwandoorganiser:id/content_main) for fragment TicketCollectorsFragment570be2e #3 id=0x7f08008a
      2018-11-14 14:19:22.741 27690-27690/com.lomakuit.phwandoorganiser E/FragmentManager: Activity state:
      2018-11-14 14:19:22.788 27690-27690/com.lomakuit.phwandoorganiser E/AndroidRuntime: FATAL EXCEPTION: main
      Process: com.lomakuit.phwandoorganiser, PID: 27690
      java.lang.IllegalArgumentException: No view found for id 0x7f08008a (com.lomakuit.phwandoorganiser:id/content_main) for fragment TicketCollectorsFragment570be2e #3 id=0x7f08008a
      at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1454)
      at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1784)
      at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1852)
      at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:802)
      at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2625)
      at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2411)
      at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2366)
      at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2273)
      at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:733)
      at android.os.Handler.handleCallback(Handler.java:789)
      at android.os.Handler.dispatchMessage(Handler.java:98)
      at android.os.Looper.loop(Looper.java:164)
      at android.app.ActivityThread.main(ActivityThread.java:6944)
      at java.lang.reflect.Method.invoke(Native Method)
      at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)





      I'm unsure of how I can switch between fragments.

      enter image description hereenter image description here







      android android-fragments android-viewpager navigation-drawer fragmenttransaction






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 14 '18 at 12:44









      amir133

      13914




      13914










      asked Nov 14 '18 at 12:24









      Manny265Manny265

      1,02331734




      1,02331734






















          1 Answer
          1






          active

          oldest

          votes


















          0














          your_activity.xml:



          <FrameLayout 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"
          app:layout_behavior="@string/appbar_scrolling_view_behavior"
          tools:context=".activities.MainActivity"
          tools:showIn="@layout/app_bar_main">


          <android.support.constraint.ConstraintLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:id="@+id/content_main">
          </android.support.constraint.ConstraintLayout>


          Something like this. Your content_main id (some layout) have to be held inside activity which you want to replace (not id of your xml parent layout [how could you call multiple fragments from it then?]).






          share|improve this answer























          • The activity_main.xml includes the app_bar_main.xml which also includes the view with the ID content_main. This is for the activities and not individual fragment. This is where I try to replace the view of that particular fragment.

            – Manny265
            Nov 19 '18 at 9:26










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53300195%2fhow-to-change-fragments-within-a-view-pager-hosted-by-a-navigation-drawer%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          your_activity.xml:



          <FrameLayout 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"
          app:layout_behavior="@string/appbar_scrolling_view_behavior"
          tools:context=".activities.MainActivity"
          tools:showIn="@layout/app_bar_main">


          <android.support.constraint.ConstraintLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:id="@+id/content_main">
          </android.support.constraint.ConstraintLayout>


          Something like this. Your content_main id (some layout) have to be held inside activity which you want to replace (not id of your xml parent layout [how could you call multiple fragments from it then?]).






          share|improve this answer























          • The activity_main.xml includes the app_bar_main.xml which also includes the view with the ID content_main. This is for the activities and not individual fragment. This is where I try to replace the view of that particular fragment.

            – Manny265
            Nov 19 '18 at 9:26















          0














          your_activity.xml:



          <FrameLayout 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"
          app:layout_behavior="@string/appbar_scrolling_view_behavior"
          tools:context=".activities.MainActivity"
          tools:showIn="@layout/app_bar_main">


          <android.support.constraint.ConstraintLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:id="@+id/content_main">
          </android.support.constraint.ConstraintLayout>


          Something like this. Your content_main id (some layout) have to be held inside activity which you want to replace (not id of your xml parent layout [how could you call multiple fragments from it then?]).






          share|improve this answer























          • The activity_main.xml includes the app_bar_main.xml which also includes the view with the ID content_main. This is for the activities and not individual fragment. This is where I try to replace the view of that particular fragment.

            – Manny265
            Nov 19 '18 at 9:26













          0












          0








          0







          your_activity.xml:



          <FrameLayout 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"
          app:layout_behavior="@string/appbar_scrolling_view_behavior"
          tools:context=".activities.MainActivity"
          tools:showIn="@layout/app_bar_main">


          <android.support.constraint.ConstraintLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:id="@+id/content_main">
          </android.support.constraint.ConstraintLayout>


          Something like this. Your content_main id (some layout) have to be held inside activity which you want to replace (not id of your xml parent layout [how could you call multiple fragments from it then?]).






          share|improve this answer













          your_activity.xml:



          <FrameLayout 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"
          app:layout_behavior="@string/appbar_scrolling_view_behavior"
          tools:context=".activities.MainActivity"
          tools:showIn="@layout/app_bar_main">


          <android.support.constraint.ConstraintLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:id="@+id/content_main">
          </android.support.constraint.ConstraintLayout>


          Something like this. Your content_main id (some layout) have to be held inside activity which you want to replace (not id of your xml parent layout [how could you call multiple fragments from it then?]).







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 16 '18 at 11:07









          SkypeDoggSkypeDogg

          8711




          8711












          • The activity_main.xml includes the app_bar_main.xml which also includes the view with the ID content_main. This is for the activities and not individual fragment. This is where I try to replace the view of that particular fragment.

            – Manny265
            Nov 19 '18 at 9:26

















          • The activity_main.xml includes the app_bar_main.xml which also includes the view with the ID content_main. This is for the activities and not individual fragment. This is where I try to replace the view of that particular fragment.

            – Manny265
            Nov 19 '18 at 9:26
















          The activity_main.xml includes the app_bar_main.xml which also includes the view with the ID content_main. This is for the activities and not individual fragment. This is where I try to replace the view of that particular fragment.

          – Manny265
          Nov 19 '18 at 9:26





          The activity_main.xml includes the app_bar_main.xml which also includes the view with the ID content_main. This is for the activities and not individual fragment. This is where I try to replace the view of that particular fragment.

          – Manny265
          Nov 19 '18 at 9:26



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53300195%2fhow-to-change-fragments-within-a-view-pager-hosted-by-a-navigation-drawer%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          How to read a connectionString WITH PROVIDER in .NET Core?

          Node.js Script on GitHub Pages or Amazon S3

          Museum of Modern and Contemporary Art of Trento and Rovereto