コードは次のとおりです: SectionsPageradapter コンストラクターの呼び出し:
mSectionsPagerAdapter = new SectionsPagerAdapter(
getSupportFragmentManager());
クラス SectionsPagerAdapter :
public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
// getItem is called to instantiate the fragment for the given page.
// Return a DummySectionFragment (defined as a static inner class
// below) with the page number as its lone argument.
Fragment fragment = new TabFragment();
Bundle args = new Bundle();
args.putInt(TabFragment.ARG_OBJECT, position);
fragment.setArguments(args);
return fragment;
}
@Override
public int getCount() {
// Show 3 total pages.
return 2;
}
@Override
public CharSequence getPageTitle(int position) {
Locale l = Locale.getDefault();
switch (position) {
case 0:
return getString(R.string.title_section1).toUpperCase(l);
case 1:
return getString(R.string.title_section2).toUpperCase(l);
}
return null;
}
}
そして TabFragment クラス:
/**
* A fragment that launches other parts of the demo application.
*/
public static class TabFragment extends Fragment {
public static final String ARG_OBJECT = "object";
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Bundle args = getArguments();
int position = args.getInt(ARG_OBJECT);
int tabLayout = 0;
switch (position) {
case 0:
tabLayout = R.layout.activity_file_list;
break;
case 1:
tabLayout = R.layout.panel_view;
break;
}
View rootView = inflater.inflate(tabLayout, container, false);
return rootView;
}
}
したがって、エラーは、 mViewPager.setAdapter(mSectionsPagerAdapter); を呼び出すときです。mSectionsPagerAdapter が null であることを示しています。
何か案は ?
ありがとう、ニック