PagerAdapter.java revision 5c1637087453de15e31861f073eae5133c4e9f7b
15c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn/* 25c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * Copyright (C) 2011 The Android Open Source Project 35c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * 45c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * Licensed under the Apache License, Version 2.0 (the "License"); 55c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * you may not use this file except in compliance with the License. 65c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * You may obtain a copy of the License at 75c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * 85c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * http://www.apache.org/licenses/LICENSE-2.0 95c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * 105c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * Unless required by applicable law or agreed to in writing, software 115c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * distributed under the License is distributed on an "AS IS" BASIS, 125c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 135c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * See the License for the specific language governing permissions and 145c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * limitations under the License. 155c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn */ 165c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn 175c1637087453de15e31861f073eae5133c4e9f7bDianne Hackbornpackage android.support.v4.view; 185c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn 195c1637087453de15e31861f073eae5133c4e9f7bDianne Hackbornimport android.os.Parcelable; 205c1637087453de15e31861f073eae5133c4e9f7bDianne Hackbornimport android.view.View; 215c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn 225c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn/** 235c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * Base class providing the adapter to populate pages inside of 245c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * a {@link ViewPager}. You will most likely want to use a more 255c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * specific implementation of this, such as 265c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * {@link android.support.v4.app.FragmentPagerAdapter} or 275c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * {@link android.support.v4.app.FragmentStatePagerAdapter}. 285c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn */ 295c1637087453de15e31861f073eae5133c4e9f7bDianne Hackbornpublic abstract class PagerAdapter { 305c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn /** 315c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * Return the number of fragments available. 325c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn */ 335c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn public abstract int getCount(); 345c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn 355c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn /** 365c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * Called when a change in the shown pages is going to start being made. 375c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * @param container The containing View which is displaying this adapter's 385c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * page views. 395c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn */ 405c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn public abstract void startUpdate(View container); 415c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn 425c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn /** 435c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * Create the page for the given position. The adapter is responsible 445c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * for adding the view to the container given here, although it only 455c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * must ensure this is done by the time it returns from 465c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * {@link #finishUpdate()}. 475c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * 485c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * @param container The containing View in which the page will be shown. 495c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * @param position The page position to be instantiated. 505c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * @return Returns an Object representing the new page. This does not 515c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * need to be a View, but can be some other container of the page. 525c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn */ 535c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn public abstract Object instantiateItem(View container, int position); 545c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn 555c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn /** 565c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * Remove a page for the given position. The adapter is responsible 575c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * for removing the view from its container, although it only must ensure 585c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * this is done by the time it returns from {@link #finishUpdate()}. 595c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * 605c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * @param container The containing View from which the page will be removed. 615c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * @param position The page position to be removed. 625c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * @param object The same object that was returned by 635c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * {@link #instantiateItem(View, int)}. 645c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn */ 655c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn public abstract void destroyItem(View container, int position, Object object); 665c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn 675c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn /** 685c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * Called when the a change in the shown pages has been completed. At this 695c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * point you must ensure that all of the pages have actually been added or 705c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * removed from the container as appropriate. 715c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * @param container The containing View which is displaying this adapter's 725c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn * page views. 735c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn */ 745c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn public abstract void finishUpdate(View container); 755c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn 765c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn public abstract boolean isViewFromObject(View view, Object object); 775c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn 785c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn public abstract Parcelable saveState(); 795c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn 805c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn public abstract void restoreState(Parcelable state, ClassLoader loader); 815c1637087453de15e31861f073eae5133c4e9f7bDianne Hackborn} 82