该功能实现了界面引导
public class ViewPagerActivity extends FragmentActivity {
private ViewPager mVPActivity;
private Fragment1 mFragment1;
private Fragment2 mFragment2;
private Fragment3 mFragment3;
private Fragment4 mFragment4;
private List
private PagerAdapter mPgAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_viewpager);
initView();
}
private void initView() {
mVPActivity = (ViewPager) findViewById(R.id.vp_activity);
mFragment1 = new Fragment1();
mFragment2 = new Fragment2();
mFragment3 = new Fragment3();
mFragment4 = new Fragment4();
mListFragment.add(mFragment1);
mListFragment.add(mFragment2);
mListFragment.add(mFragment3);
mListFragment.add(mFragment4);
mPgAdapter = new ViewPagerAdapter(getSupportFragmentManager(),
mListFragment);
mVPActivity.setAdapter(mPgAdapter);
}
}
ViewPager适配器代码如下所示
public class ViewPagerAdapter extends FragmentPagerAdapter {
private List
public ViewPagerAdapter(FragmentManager fm) {
super(fm);
}
public ViewPagerAdapter(FragmentManager fragmentManager,List
super(fragmentManager);
this.fragmentList=arrayList;
}
@Override
public Fragment getItem(int arg0) {
return fragmentList.get(arg0);
}
@Override
public int getCount() {
return fragmentList.size();
}
}