0
我正在嘗試開發基於選項卡的應用程序。每個選項卡都有其片段。其中之一有ViewPager,而ViewPager有自己的頁面。我通過在這個viewpager中滾動來移動到另一個。FragmentPagerAdapter類僅在第一次單擊選項卡時觸發
當我第一次打開應用程序時,沒有問題。但是,當我從此選項卡移動到另一個選項卡時,它不顯示viewpager內容,它不會觸發FragmentPagerAdapter類。
選項卡A - 標籤乙 - 製表符Ç
選項卡C語言程序段具有的ViewPage。
ViewPage有它自己的頁面。
public class FragmentC extends Fragment {
public static final String ARG_SECTION_NUMBER = "section_number";
static ViewPager C_mViewPager;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
C_mViewPager = (ViewPager)inflater.inflate(R.layout.fragmentC, container,false);
C_SectionsPagerAdapter mC_PagerAdapter=new C_SectionsPagerAdapter(MainActivity.fragmentManagerv4);
C_mViewPager.setAdapter(mC_PagerAdapter);
return C_mViewPager;
}
public class C_SectionsPagerAdapter extends FragmentPagerAdapter {
public C_SectionsPagerAdapter (FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int i) {
Fragment fragment = null ;
Bundle args;
switch (i) {
case 0:
fragment=new A_SubFragment();
break;
case 1:
fragment = new B_SubFragment();
break;
case 2:
fragment = new C_SubFragment();
break;
case 3:
fragment = new D_SubFragment();
break;
}
return fragment;
}
@Override
public int getCount() {
return 4;
}
@Override
public CharSequence getPageTitle(int position) {
switch (position) {
case 0: return getString(R.string.title_section1).toUpperCase();
case 1: return getString(R.string.title_section2).toUpperCase();
case 2: return getString(R.string.title_section3).toUpperCase();
case 3: return getString(R.string.title_section4).toUpperCase();
}
return null;
}
}
public static class A_SubFragment extends Fragment {
public A_SubFragment() {
}
public static final String ARG_SECTION_NUMBER = "section_number";
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
RelativeLayout theLayout=(RelativeLayout)inflater.inflate(R.layout.a_sub_fragment, container,false);
//...
return theLayout;}}
}
F片段C;
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" />
它不火的getItem方法。 – essbek