When writing pageradapter, you need to rewrite Instantiateitem (viewgroup container, int position)
In this method, the view that will need to be loaded is added to the container.
Pageradapter cannot use viewholder like a ListView directly to enable the reuse of a view. Therefore, if each load, a new view will be a very memory-intensive. If your view is all the same, such as ImageView, then you can use a list to save the recovered view and load it again, preferably from the Recycle list, no need to go to new. The approximate logic is as follows: Private LinkedList<View> recycledviews= New LinkedList<View> (); Public ObjectInstantiateitem(ViewGroup Container , int position ) { // TODO auto-generated method Stub CustomimageImageView= null; if (Debug ) Log.e (TAG, "Pageradapter:instantiateitem"+"position is"+String .valueOf(position)+ "ChildCount is:" +Container.Getchildcount()); if (recycledviews != NULL &&recycledviews.size()>0) {ImageView= (Customimage)recycledviews .GetFirst();recycledviews.Removefirst(); } Else {ImageView= New Customimage(Mcontext); }ImageView.Setimageresource(Resids.Get(position)); Container .AddView(ImageView); returnImageView; } @Override Public voidDestroyitem(ViewGroup Container , int position , Object Object) { // TODO auto-generated method Stub if (Debug ) Log.e (TAG, "Pageradapter:destroyitem"+"position is"+String .valueOf(position)+"ChildCount is:" +Container.Getchildcount()); ((ViewGroup) Container ).Removeview ((View) Object ); if (Object !=NULL) {recycledviews.AddLast((View)Object); } } the above customview is my custom imageview, can use any view instead. The same effect.
The reuse of view in Android Viewpager Pageradapter