Android FragmentPagerAdapter不显示内容

Android FragmentPagerAdapter不显示内容,android,android-fragments,android-viewpager,Android,Android Fragments,Android Viewpager,使用FragmentPagerAdapter的My view pager实现没有显示任何内容。我试图将其更改为FragmentStatePagerAdapter,但毫无帮助 主要活动类 public enum TYPES { OBJECT_TYPE, TRACKS} @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstan

使用
FragmentPagerAdapter
的My view pager实现没有显示任何内容。我试图将其更改为
FragmentStatePagerAdapter
,但毫无帮助

主要活动类

   public enum TYPES {
        OBJECT_TYPE, TRACKS}
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        SimpleObject simpleObject = new SimpleObject("left","inside","right");
        ViewPager viewPager = (ViewPager)findViewById(R.id.visitMuseumPager);
        viewPager.setAdapter(new ViewPagerAdapter(this.getSupportFragmentManager(), simpleObject, TYPES.TRACKS));
    }
ViewPagerAdapter

public class ViewPagerAdapter extends FragmentStatePagerAdapter {

private SimpleObject simpleObject;
MainActivity.TYPES type;
public ViewPagerAdapter(FragmentManager fm, SimpleObject simpleObjects, MainActivity.TYPES type) {
    super(fm);
    this.simpleObject =simpleObjects;
    this.type=type;
}

@Override
public Object instantiateItem(ViewGroup container, int position) {
    return super.instantiateItem(container, position);
}

@Override
public Fragment getItem(int position) {
    Bundle bundle = new Bundle();
    bundle.putParcelable("simpleObject", simpleObject);
    if(type.equals(TRACKS)){
    switch (position){
        case 0:{
          LeftFragment  leftFragment = new LeftFragment();
            leftFragment.setArguments(bundle);
            return leftFragment;
        }
        case 1:{
            InsideFragment insideFragment = new InsideFragment();
            insideFragment.setArguments(bundle);
            return insideFragment;
        }
        case 2:{
            RightFragment rightFragment = new RightFragment();
            rightFragment.setArguments(bundle);
        return rightFragment;
        }
    }}
    else if (type.equals(OBJECT_TYPE)){
        switch (position){
        case 0:{
            LeftFragment  leftFragment = new LeftFragment();
            leftFragment.setArguments(bundle);
            return leftFragment;
        }
        case 1:{
            InsideFragment insideFragment = new InsideFragment();
            insideFragment.setArguments(bundle);
            return insideFragment;
        }}
    }

    return null;
}

 @Override
public int getCount() {

    if (type.equals(TRACKS))return 3;
    else return 2;
}}
public class LeftFragment extends Fragment {


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
       View view = inflater.inflate(R.layout.left_tab, container, false);
        TextView textView=(TextView) view.findViewById(R.id.leftTab);
        SimpleObject simpleObject = getArguments().getParcelable("simpleObject");
        textView.setText(simpleObject.getLeftVal());
        return view;
    }
}
片段实现(其余部分类似)


主要活动XML

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.k.testy.MainActivity"
android:orientation="vertical"
android:weightSum="1">



<android.support.v4.view.ViewPager
    android:id="@+id/visitMuseumPager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:visibility="gone"
    android:animateLayoutChanges="true"
    /></LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1"
android:background="@color/black">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight=".1">
    <include layout="@layout/tab_buttons"/>
</LinearLayout>

<TextView
    android:id="@+id/leftTab"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:text="LEFT"/>


左片段XML

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.k.testy.MainActivity"
android:orientation="vertical"
android:weightSum="1">



<android.support.v4.view.ViewPager
    android:id="@+id/visitMuseumPager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:visibility="gone"
    android:animateLayoutChanges="true"
    /></LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1"
android:background="@color/black">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight=".1">
    <include layout="@layout/tab_buttons"/>
</LinearLayout>

<TextView
    android:id="@+id/leftTab"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:text="LEFT"/>


从XML格式的ViewPager中删除

android:visibility="gone"

从XML格式的ViewPager中删除

android:visibility="gone"