2017-03-02 29 views
0

FragmentPagerAdapterのビューページャーの実装には何も表示されません。私はそれをFragmentStatePagerAdapterに変更しようとしましたが、それは全く助けになりません。FragmentPagerAdapterにコンテンツが表示されない

主な活動は、クラス

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> 


左断片XML

<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"/> 

答えて

2

XMLでViewPagerから

0123を削除します
+0

:どのように私はそれを見逃すことができます、ありがとう:D – Expiredmind

関連する問題