Pageradapter Summary in Android

Source: Internet
Author: User

Pageradapter Introduction

Pageradapter is the class in the ANDROID.SUPPORT.V4 package, its subclasses have Fragmentpageradapter, Fragmentstatepageradapter, These two adapter are fragment adapters, used to achieve the fragment sliding effect, the use of the two adapter and the difference is not introduced this time.

The Pageradapter is primarily a viewpager adapter, And Viewpager is also in the ANDROID.SUPPORT.V4 expansion package added a powerful control, you can implement the sliding effect of the control, such as our software common in the banner of the sliding effect, with the Viewpager can be achieved. Today, we mainly introduce how to use VIEWPAGR and rewrite pageradapter to achieve the sliding effect of common banner.

Introduction to Pageradapter Usage

First, if you inherit Pageradapter, you must override the following four methods at a minimum:

1. Instantiateitem (ViewGroup, int.)
2. Destroyitem (viewgroup, int, Object)
3. GetCount ()
4. Isviewfromobject (View, Object)
Below we describe the meaning of these four methods and how to use them in the form of a code:

Private classViewpageradapterextendsPageradapter {//get the number of controls to slide, here we take the sliding banner as an example, then this should be the number of ImageView of the displayed ad image@Override Public intGetCount () {returnimages.size (); }        //to determine whether the same picture is displayed, here we compare two parameters to return@Override Public BooleanIsviewfromobject (View arg0, Object arg1) {returnarg0 = =arg1; }        //Pageradapter only caches three images to be displayed, and if the sliding picture goes beyond the cached range, this method is called to destroy the image .@Override Public voidDestroyitem (ViewGroup view,intposition, Object object)        {View.removeview (Images.get (position)); }        //when the image to be displayed can be cached, this method is called to initialize the display image, and we will add the ImageView to the ViewGroup and return it as the return value .@Override PublicObject Instantiateitem (ViewGroup view,intposition)            {View.addview (Images.get (position)); returnImages.get (position); }    }

Pageradapter Summary in Android

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.