ViewPager放在Fragment中怎么实现
我把ViewPager放在Fragment中的,但是程序运行后,滑到最后一页的时候,程序就异常退出了?怎么回事
public class FirstFragment extends Fragment{ private ViewPager mViewPager; private int[] mImagIds = new int[]{R.mipmap.viewpager_1,R.mipmap.viewpager_2,R.mipmap.viewpager_3}; private List<View> mImages = new ArrayList<View>(); public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState){ View view = inflater.inflate(R.layout.first_fragment,container,false); mViewPager = (ViewPager) view.findViewById(R.id.viewpager); mViewPager.setAdapter(new PagerAdapter() { @Override public Object instantiateItem(ViewGroup container, int position) { ImageView imageview = new ImageView(getActivity()); imageview.setImageResource(mImagIds[position]); imageview.setScaleType(ImageView.ScaleType.CENTER_CROP); container.addView(imageview); return imageview; } @Override public void destroyItem(ViewGroup container, int position, Object object) { container.removeView(mImages.get(position)); } @Override public int getCount() { return mImagIds.length; } @Override public boolean isViewFromObject(View view, Object object) { return view == object; } }); return view; }