Android fragments 在Android中,如何替换表格布局中的片段?

Android fragments 在Android中,如何替换表格布局中的片段?,android-fragments,android-viewpager,android-fragmentactivity,android-tablayout,Android Fragments,Android Viewpager,Android Fragmentactivity,Android Tablayout,看在上帝的份上,我似乎无法理解这一点。我有一个包含3个选项卡的表格(每个选项卡中都有一个片段)。我要做的就是在第二个片段上,用户单击一个按钮,它用一个新片段替换第二个选项卡的片段。那我该怎么做呢 这是我要替换的片段的xml <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:la

看在上帝的份上,我似乎无法理解这一点。我有一个包含3个选项卡的表格(每个选项卡中都有一个片段)。我要做的就是在第二个片段上,用户单击一个按钮,它用一个新片段替换第二个选项卡的片段。那我该怎么做呢

这是我要替换的片段的xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/fragCards_mainLL">
    <android.support.v4.widget.NestedScrollView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="true">
        <LinearLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:paddingTop="24dp"
            android:id="@+id/fragCards_LL">

            <android.support.v7.widget.RecyclerView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/fragCards_RecyclerView">
            </android.support.v7.widget.RecyclerView>

        </LinearLayout>
    </android.support.v4.widget.NestedScrollView>
</FrameLayout>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.daprlabs.swipedeck.ProfileView.FragmentFollowers"
    android:id="@+id/fragFollowrs_mainFL">

    <!-- TODO: Update blank fragment layout -->
    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="Followers Fragment"
        android:gravity="center"
        android:textSize="30dp"/>

</FrameLayout>
public class ViewPagerAdapter extends FragmentPagerAdapter
{
    ArrayList<Fragment> fragments = new ArrayList<>();
    ArrayList<String> tabTitles = new ArrayList<>();

    public ViewPagerAdapter(android.support.v4.app.FragmentManager fragmentManager)
    {
        super(fragmentManager);
    }
    @Override
    public Fragment getItem(int position)
    {
        return fragments.get(position);
    }
    @Override
    public int getCount()
    {
        return fragments.size();
    }
    @Override
    public CharSequence getPageTitle(int position)
    {
        return tabTitles.get(position);
    }
    public void addFragments(Fragment fragment, String titles)
    {
        this.fragments.add(fragment);
        this.tabTitles.add(titles);
    }
}
                @Override
                public void onClick(View v)
                {
                    FragmentFollowers f1 = new FragmentFollowers();
                    android.support.v4.app.FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
                    fragmentTransaction.replace(R.id.fragCards_LL,f1);
                    fragmentTransaction.setTransition(android.support.v4.app.FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
                    fragmentTransaction.addToBackStack(null);
                    fragmentTransaction.commit();
                    Toast.makeText(getActivity(),"position  " +position,Toast.LENGTH_SHORT).show();
                }