PagerAdapter.java revision 5c1637087453de15e31861f073eae5133c4e9f7b
1/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.support.v4.view;
18
19import android.os.Parcelable;
20import android.view.View;
21
22/**
23 * Base class providing the adapter to populate pages inside of
24 * a {@link ViewPager}.  You will most likely want to use a more
25 * specific implementation of this, such as
26 * {@link android.support.v4.app.FragmentPagerAdapter} or
27 * {@link android.support.v4.app.FragmentStatePagerAdapter}.
28 */
29public abstract class PagerAdapter {
30    /**
31     * Return the number of fragments available.
32     */
33    public abstract int getCount();
34
35    /**
36     * Called when a change in the shown pages is going to start being made.
37     * @param container The containing View which is displaying this adapter's
38     * page views.
39     */
40    public abstract void startUpdate(View container);
41
42    /**
43     * Create the page for the given position.  The adapter is responsible
44     * for adding the view to the container given here, although it only
45     * must ensure this is done by the time it returns from
46     * {@link #finishUpdate()}.
47     *
48     * @param container The containing View in which the page will be shown.
49     * @param position The page position to be instantiated.
50     * @return Returns an Object representing the new page.  This does not
51     * need to be a View, but can be some other container of the page.
52     */
53    public abstract Object instantiateItem(View container, int position);
54
55    /**
56     * Remove a page for the given position.  The adapter is responsible
57     * for removing the view from its container, although it only must ensure
58     * this is done by the time it returns from {@link #finishUpdate()}.
59     *
60     * @param container The containing View from which the page will be removed.
61     * @param position The page position to be removed.
62     * @param object The same object that was returned by
63     * {@link #instantiateItem(View, int)}.
64     */
65    public abstract void destroyItem(View container, int position, Object object);
66
67    /**
68     * Called when the a change in the shown pages has been completed.  At this
69     * point you must ensure that all of the pages have actually been added or
70     * removed from the container as appropriate.
71     * @param container The containing View which is displaying this adapter's
72     * page views.
73     */
74    public abstract void finishUpdate(View container);
75
76    public abstract boolean isViewFromObject(View view, Object object);
77
78    public abstract Parcelable saveState();
79
80    public abstract void restoreState(Parcelable state, ClassLoader loader);
81}
82