ViewPager放在Fragment中怎么實(shí)現(xiàn)
我把ViewPager放在Fragment中的,但是程序運(yùn)行后,滑到最后一頁(yè)的時(shí)候,程序就異常退出了?怎么回事
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; ????}
2018-02-22
沒(méi)有把imageview放到mImages中