title: I want to initialize the fragment every time the bottom navigation item is selected
body: <p>The code below is a function that runs when bottomNavigation is clicked.</p>
  <pre><code>fun replaceFragment(fragment: Fragment)// 프래그먼트 교체 함수
      {
          Log.d(&quot;MainAcitvity&quot;, &quot;fragment replace + $fragment&quot;)
  
          //Fragment Start Remove
          supportFragmentManager.beginTransaction().apply {
              remove(fragment)
              commit()
          }
  
          //Fragment Start Replace
          supportFragmentManager.beginTransaction().apply {
  
              replace(R.id.fragmentContainer, fragment)
              commit()
              Log.d(&quot;MainAcitvity&quot;, &quot;fragment replace start + $fragment&quot;)
          }
  
      }//end of replaceFragment
  
  </code></pre>
  <pre><code>bottomNavigationView.setOnNavigationItemSelectedListener {
              when (it.itemId) {
                  R.id.fragment1 -&gt; {
                      adjustGravity(bottomNavigationView)
  
                  }
                  R.id.fragment2 -&gt; {
                      replaceFragment(Fragment2)
                  }
                  R.id.fragment3 -&gt; {
                      replaceFragment(Fragment3)
                  }
                  R.id.fragment4 -&gt; {
                      replaceFragment(Fragment4)
                  }
              }
              true 
          }//end of setOnNavigationItemSelectedListener
  </code></pre>
  <p>But this is not working.</p>
  <p>I'm trying to do this because I'm using CoordinatorLayout to scroll up the AppLayout function.</p>
  <p><a href="https://i.stack.imgur.com/0mfDI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0mfDI.png" alt="enter image description here" /></a></p>
  <p><a href="https://i.stack.imgur.com/k4npO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/k4npO.png" alt="enter image description here" /></a></p>
  <p>When I scroll down and go to the other Fragment,
  It's not initializing as you can see in the picture above.</p>
  <p>In NestedScrollView, the On Pause() for each Fragment will be displayed in the
  I tried NestedScrollView.scrollTo(0,0), but it doesn't work.</p>
  <p>I've also tried initializing OnCreateView(), but it doesn't work either.</p>
  <p>I think the Fragments are working in MainActivity and the life cycle is a problem.</p>
  <p>Below is an example of one of the Fragments.</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;androidx.constraintlayout.widget.ConstraintLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
      xmlns:tools=&quot;http://schemas.android.com/tools&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;match_parent&quot;&gt;
  
      &lt;androidx.coordinatorlayout.widget.CoordinatorLayout
          android:id=&quot;@+id/CoordinatorLayout&quot;
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;match_parent&quot;&gt;
  
          &lt;com.google.android.material.appbar.AppBarLayout
              android:id=&quot;@+id/fragment3ToolbarFrame&quot;
              android:layout_width=&quot;match_parent&quot;
              android:layout_height=&quot;290dp&quot;
              android:background=&quot;@android:color/transparent&quot;
              android:fitsSystemWindows=&quot;true&quot;&gt;
  
              &lt;com.google.android.material.appbar.CollapsingToolbarLayout
                  android:layout_width=&quot;match_parent&quot;
                  android:layout_height=&quot;match_parent&quot;
                  android:minHeight=&quot;50dp&quot;
                  app:layout_scrollFlags=&quot;scroll|exitUntilCollapsed&quot;&gt;
  
                  &lt;ImageView
                      android:id=&quot;@+id/fragment3ImageView&quot;
                      android:layout_width=&quot;match_parent&quot;
                      android:layout_height=&quot;match_parent&quot;
                      android:background=&quot;@color/talk_toolbar_color&quot; /&gt;
  
                  &lt;TextView
                      android:layout_width=&quot;wrap_content&quot;
                      android:layout_height=&quot;wrap_content&quot;
                      android:layout_marginStart=&quot;@dimen/fragment3_title_margin_start&quot;
                      android:layout_marginTop=&quot;@dimen/fragment3_title_margin_top&quot;
                      android:fontFamily=&quot;@font/notosanscjkkr_medium&quot;
                      android:includeFontPadding=&quot;false&quot;
                      android:text=&quot;@string/fragment3_tag_title&quot;
                      android:textColor=&quot;@color/white&quot;
                      android:textSize=&quot;@dimen/fragment3_title_size&quot; /&gt;
  
                  &lt;TextView
                      android:layout_width=&quot;wrap_content&quot;
                      android:layout_height=&quot;wrap_content&quot;
                      android:layout_marginStart=&quot;@dimen/fragment3_subtitle_margin_start&quot;
                      android:layout_marginTop=&quot;@dimen/fragment3_subtitle1_margin_top&quot;
                      android:fontFamily=&quot;@font/notosanscjkkr_regular&quot;
                      android:includeFontPadding=&quot;false&quot;
                      android:text=&quot;@string/fragment3_tag_subtitle1&quot;
                      android:textColor=&quot;@color/white&quot;
                      android:textSize=&quot;@dimen/fragment3_subtitle_size&quot; /&gt;
  
                  &lt;TextView
                      android:id=&quot;@+id/fragment3_tagText3&quot;
                      android:layout_width=&quot;wrap_content&quot;
                      android:layout_height=&quot;wrap_content&quot;
                      android:layout_marginStart=&quot;@dimen/fragment3_subtitle_margin_start&quot;
                      android:layout_marginTop=&quot;175dp&quot;
                      android:fontFamily=&quot;@font/notosanscjkkr_regular&quot;
                      android:includeFontPadding=&quot;false&quot;
                      android:text=&quot;@string/fragment3_tag_subtitle2&quot;
                      android:textColor=&quot;@color/white&quot;
                      android:textSize=&quot;12dp&quot; /&gt;
  
                  &lt;TextView
                      android:id=&quot;@+id/fragment3AppbarTextView&quot;
                      android:layout_width=&quot;wrap_content&quot;
                      android:layout_height=&quot;wrap_content&quot;
                      android:layout_marginStart=&quot;36dp&quot;
                      android:layout_marginTop=&quot;225dp&quot;
                      android:fontFamily=&quot;@font/notosanscjkkr_medium&quot;
                      android:includeFontPadding=&quot;false&quot;
                      android:text=&quot;@string/fragment3_tag_title&quot;
                      android:textColor=&quot;@color/white&quot;
                      android:textSize=&quot;50sp&quot;
                      android:visibility=&quot;gone&quot; /&gt;
  
              &lt;/com.google.android.material.appbar.CollapsingToolbarLayout&gt;
          &lt;/com.google.android.material.appbar.AppBarLayout&gt;
  
          &lt;androidx.core.widget.NestedScrollView
              android:id=&quot;@+id/fragment3NestedScrollView&quot;
              android:layout_width=&quot;match_parent&quot;
              android:layout_height=&quot;match_parent&quot;
              app:layout_behavior=&quot;com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior&quot;&gt;
  
              &lt;androidx.constraintlayout.widget.ConstraintLayout
                  android:layout_width=&quot;match_parent&quot;
                  android:layout_height=&quot;match_parent&quot;
                  app:layout_behavior=&quot;com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior&quot;&gt;
  
                  &lt;androidx.recyclerview.widget.RecyclerView
                      android:id=&quot;@+id/fragment3RecyclerView&quot;
                      android:layout_width=&quot;0dp&quot;
                      android:layout_height=&quot;wrap_content&quot;
                      android:layout_margin=&quot;20dp&quot;
                      app:layout_constraintEnd_toEndOf=&quot;parent&quot;
                      app:layout_constraintStart_toStartOf=&quot;parent&quot;
                      app:layout_constraintTop_toTopOf=&quot;parent&quot; /&gt;
  
              &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
          &lt;/androidx.core.widget.NestedScrollView&gt;
      &lt;/androidx.coordinatorlayout.widget.CoordinatorLayout&gt;
  
      &lt;com.google.android.material.floatingactionbutton.FloatingActionButton
          android:id=&quot;@+id/addFloatingButton&quot;
          android:layout_width=&quot;wrap_content&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:layout_margin=&quot;16dp&quot;
          android:backgroundTint=&quot;#447BE3&quot;
          android:src=&quot;@drawable/ic_baseline_create_24&quot;
          app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
          app:layout_constraintEnd_toEndOf=&quot;parent&quot;
          app:tint=&quot;@null&quot; /&gt;
  
  &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  </code></pre>
  <p>I want to initialize the Fragment by any means. Is there any way?</p>