2017-03-02 6 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; 
    } 
} 
(그들 중 나머지는 비슷한입니다)


주요 활동

<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에서 제거 XML

android:visibility="gone" 
+0

: O 어떻게 그, 감사를 놓칠 수 있습니다 : D 조 – Expiredmind

관련 문제