title: Replacement fragments in in pagerView
body: <p>`Facing one problem in android that I created a pager View and two fragments lets say fragment A and fragment B are attached...</p>
  <p>My question is: There is a button in fragment A after clicking on that button I want to load fragment C which will be the replacement of fragment A in the same pager view how can it be done? But when I try below code content of Fragment C is shown over the fragment A ... can u help me with this please. I searched everywhere but didn't get the proper solution.
  here is my code...</p>
  <pre><code>public class MainActivity extends AppCompatActivity implements Top_Fragment.OnFragmentInteractionListener {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          Toolbar toolbar=findViewById(R.id.tool_bar);
          setSupportActionBar(toolbar);
  
          MyPagerAdapter myPagerAdapter = new MyPagerAdapter(getSupportFragmentManager());
          ViewPager viewPager = findViewById(R.id.pagerView);
          viewPager.setAdapter(myPagerAdapter);
          TabLayout tabLayout=findViewById(R.id.tab_bar);
          tabLayout.setupWithViewPager(viewPager);
  
  
  
      }
  
      class MyPagerAdapter extends FragmentPagerAdapter {
          public MyPagerAdapter(@NonNull FragmentManager fm) {
              super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
          }
  
          @Override
          public Fragment getItem(int position) {
  
              switch (position) {
                  case 0:
                      return new Top_Fragment();
                  case 1:
                      return new FavoriteFrag();
              }
              return null;
          }
  
          @Override
          public int getCount() {
              return 2;
          }
  
          @Nullable
          @Override
          public CharSequence getPageTitle(int position) {
              switch (position) {
                  case 0:
                      return getResources().getString(R.string.Items);
                  case 1:
                      return getResources().getString(R.string.favoriteItems);
              }
              return null;
          }
      }
  
      @Override
      public void onFragmentInteraction(int position) {
          Fragment fragment=null;
          switch (position){
              case 0:
                  fragment=new DrikCategaryFrag();
          }
          FragmentTransaction ft=getSupportFragmentManager().beginTransaction();
          ft.replace(R.id.frameContainer,fragment);
          ft.commit();
      }
  }
  </code></pre>
  <p>Main activity layout</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;LinearLayout 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;
  android:orientation=&quot;vertical&quot;
  tools:context=&quot;.MainActivity&quot;&gt;
  
  &lt;com.google.android.material.appbar.AppBarLayout
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;wrap_content&quot;
      android:theme=&quot;@style/ThemeOverlay.AppCompat.Dark.ActionBar&quot;&gt;
  
      &lt;androidx.appcompat.widget.Toolbar
          android:id=&quot;@+id/tool_bar&quot;
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;?attr/actionBarSize&quot;
          android:theme=&quot;@style/ThemeOverlay.AppCompat.Dark.ActionBar&quot; /&gt;
  
      &lt;com.google.android.material.tabs.TabLayout
          android:id=&quot;@+id/tab_bar&quot;
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;wrap_content&quot; /&gt;
  
  
  &lt;/com.google.android.material.appbar.AppBarLayout&gt;
  
  &lt;FrameLayout
      android:id=&quot;@+id/frameContainer&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;match_parent&quot;&gt;
  
      &lt;androidx.viewpager.widget.ViewPager
          android:id=&quot;@+id/pagerView&quot;
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;match_parent&quot;&gt;
  
  &lt;/androidx.viewpager.widget.ViewPager&gt;
  &lt;/FrameLayout&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>