# FragmentPagerAdapter

Artifact: [androidx.fragment:fragment](https://developer.android.com/jetpack/androidx/releases/fragment) [View Source](https://cs.android.com/search?q=file:androidx/fragment/app/FragmentPagerAdapter.java+class:androidx.fragment.app.FragmentPagerAdapter) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.1.0) Deprecated in [1.3.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.3.0)

*** ** * ** ***


```
abstract class FragmentPagerAdapter : PagerAdapter
```

<br />

|---|---|---|
| [kotlin.Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html) |||
| ↳ | [androidx.viewpager.widget.PagerAdapter](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter) ||
|   | ↳ | [androidx.fragment.app.FragmentPagerAdapter](https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentPagerAdapter) |

*** ** * ** ***

> [!CAUTION]
> **This class is deprecated.**   
>
> Switch to `https://developer.android.com/reference/kotlin/androidx/viewpager2/widget/ViewPager2` and use `https://developer.android.com/reference/kotlin/androidx/viewpager2/adapter/FragmentStateAdapter` instead.

Implementation of `https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter` that represents each page as a `https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment` that is persistently kept in the fragment manager as long as the user can return to the page.

This version of the pager is best for use when there are a handful of typically more static fragments to be paged through, such as a set of tabs. The fragment of each page the user visits will be kept in memory, though its view hierarchy may be destroyed when not visible. This can result in using a significant amount of memory since fragment instances can hold on to an arbitrary amount of state. For larger sets of pages, consider `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentStatePagerAdapter`.

When using FragmentPagerAdapter the host ViewPager must have a valid ID set.

Subclasses only need to implement `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentPagerAdapter#getItem(int)` and `https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#getCount()` to have a working adapter.
Here is an example implementation of a pager containing fragments of lists:

```java
public class FragmentPagerSupport extends FragmentActivity {
    static final int NUM_ITEMS = 10;

    MyAdapter mAdapter;

    ViewPager mPager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fragment_pager);

        mAdapter = new MyAdapter(getSupportFragmentManager());

        mPager = (ViewPager)findViewById(R.id.pager);
        mPager.setAdapter(mAdapter);

        // Watch for button clicks.
        Button button = (Button)findViewById(R.id.goto_first);
        button.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                mPager.setCurrentItem(0);
            }
        });
        button = (Button)findViewById(R.id.goto_last);
        button.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                mPager.setCurrentItem(NUM_ITEMS-1);
            }
        });
    }

    public static class MyAdapter extends FragmentPagerAdapter {
        public MyAdapter(FragmentManager fm) {
            super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
        }

        @Override
        public int getCount() {
            return NUM_ITEMS;
        }

        @Override
        public Fragment getItem(int position) {
            return ArrayListFragment.newInstance(position);
        }
    }

    public static class ArrayListFragment extends ListFragment {
        int mNum;

        /**
         * Create a new instance of CountingFragment, providing "num"
         * as an argument.
         */
        static ArrayListFragment newInstance(int num) {
            ArrayListFragment f = new ArrayListFragment();

            // Supply num input as an argument.
            Bundle args = new Bundle();
            args.putInt("num", num);
            f.setArguments(args);

            return f;
        }

        /**
         * When creating, retrieve this instance's number from its arguments.
         */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            mNum = getArguments() != null ? getArguments().getInt("num") : 1;
        }

        /**
         * The Fragment's UI is just a simple text view showing its
         * instance number.
         */
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            View v = inflater.inflate(R.layout.fragment_pager_list, container, false);
            View tv = v.findViewById(R.id.text);
            ((TextView)tv).setText("Fragment #" + mNum);
            return v;
        }

        @Override
        public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
            super.onViewCreated(view, savedInstanceState);
            setListAdapter(new ArrayAdapter<String>(getActivity(),
                    android.R.layout.simple_list_item_1, Cheeses.sCheeseStrings));
        }

        @Override
        public void onListItemClick(ListView l, View v, int position, long id) {
            Log.i("FragmentList", "Item clicked: " + id);
        }
    }
}
```
The `R.layout.fragment_pager`resource of the top-level fragment is:

```xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:padding="4dip"
        android:gravity="center_horizontal"
        android:layout_width="match_parent" android:layout_height="match_parent">

    <androidx.viewpager.widget.ViewPager
            android:id="@+id/pager"
            android:layout_width="match_parent"
            android:layout_height="0px"
            android:layout_weight="1">
    </androidx.viewpager.widget.ViewPager>

    <LinearLayout android:orientation="horizontal"
            android:gravity="center" android:measureWithLargestChild="true"
            android:layout_width="match_parent" android:layout_height="wrap_content"
            android:layout_weight="0">
        <Button android:id="@+id/goto_first"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:text="@string/first">
        </Button>
        <Button android:id="@+id/goto_last"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:text="@string/last">
        </Button>
    </LinearLayout>
</LinearLayout>
```
The `R.layout.fragment_pager_list`resource containing each individual fragment's layout is:

```xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:drawable/gallery_thumb">

    <TextView android:id="@+id/text"
        android:layout_width="match_parent" android:layout_height="wrap_content"
        android:gravity="center_vertical|center_horizontal"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="@string/hello_world"/>

    <!-- The frame layout is here since we will be showing either
    the empty view or the list view.  -->
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:layout_weight="1" >
        <!-- Here is the list. Since we are using a ListActivity, we
             have to call it "@android:id/list" so ListActivity will
             find it -->
        <ListView android:id="@android:id/list"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:drawSelectorOnTop="false"/>

        <!-- Here is the view to show if the list is empty -->
        <TextView android:id="@android:id/empty"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="No items."/>

    </FrameLayout>

</LinearLayout>
```

## Summary

| ### Constants |
|---|---|
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentPagerAdapter#BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT() = 1` **This property is deprecated.** Deprecated in Java |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentPagerAdapter#BEHAVIOR_SET_USER_VISIBLE_HINT() = 0` **This property is deprecated.** This behavior relies on the deprecated `https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment#setUserVisibleHint(boolean)` API. <br /> |

| ### Public constructors |
|---|
| `[FragmentPagerAdapter](https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentPagerAdapter#FragmentPagerAdapter(androidx.fragment.app.FragmentManager))(fm: https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentManager)` **This function is deprecated.** use `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentPagerAdapter#FragmentPagerAdapter(androidx.fragment.app.FragmentManager,int)` with `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentPagerAdapter#BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT()` <br /> |
| `[FragmentPagerAdapter](https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentPagerAdapter#FragmentPagerAdapter(androidx.fragment.app.FragmentManager,int))(fm: https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentManager, behavior: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` **This function is deprecated.** Deprecated in Java |

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `[destroyItem](https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentPagerAdapter#destroyItem(android.view.ViewGroup,int,java.lang.Object))(container: https://developer.android.com/reference/android/view/ViewGroup.html, position: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, object: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)` **This function is deprecated.** Deprecated in Java |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `[finishUpdate](https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentPagerAdapter#finishUpdate(android.view.ViewGroup))(container: https://developer.android.com/reference/android/view/ViewGroup.html)` **This function is deprecated.** Deprecated in Java |
| `abstract https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment` | `[getItem](https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentPagerAdapter#getItem(int))(position: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` **This function is deprecated.** Deprecated in Java |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | `[getItemId](https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentPagerAdapter#getItemId(int))(position: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` **This function is deprecated.** Deprecated in Java |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html` | `[instantiateItem](https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentPagerAdapter#instantiateItem(android.view.ViewGroup,int))(container: https://developer.android.com/reference/android/view/ViewGroup.html, position: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` **This function is deprecated.** Deprecated in Java |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `[isViewFromObject](https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentPagerAdapter#isViewFromObject(android.view.View,java.lang.Object))(view: https://developer.android.com/reference/android/view/View.html, object: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)` **This function is deprecated.** Deprecated in Java |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `[restoreState](https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentPagerAdapter#restoreState(android.os.Parcelable,java.lang.ClassLoader))(state: https://developer.android.com/reference/android/os/Parcelable.html?, loader: https://developer.android.com/reference/java/lang/ClassLoader.html?)` **This function is deprecated.** Deprecated in Java |
| `https://developer.android.com/reference/android/os/Parcelable.html?` | `[saveState](https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentPagerAdapter#saveState())()` **This function is deprecated.** Deprecated in Java |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `[setPrimaryItem](https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentPagerAdapter#setPrimaryItem(android.view.ViewGroup,int,java.lang.Object))(container: https://developer.android.com/reference/android/view/ViewGroup.html, position: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, object: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)` **This function is deprecated.** Deprecated in Java |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `[startUpdate](https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentPagerAdapter#startUpdate(android.view.ViewGroup))(container: https://developer.android.com/reference/android/view/ViewGroup.html)` **This function is deprecated.** Deprecated in Java |

### Inherited Constants

From [androidx.viewpager.widget.PagerAdapter](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter) `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` `https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#POSITION_NONE() = -2`

**This property is deprecated.** Deprecated in Java
`const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` `https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#POSITION_UNCHANGED() = -1`

**This property is deprecated.** Deprecated in Java

### Inherited functions

From [androidx.viewpager.widget.PagerAdapter](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter) `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `[destroyItem](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#destroyItem(android.view.View,int,java.lang.Object))(container: https://developer.android.com/reference/android/view/View.html, position: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, object: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)`

**This function is deprecated.**

Use `https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#destroyItem(android.view.ViewGroup,int,java.lang.Object)`

<br />

`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `[finishUpdate](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#finishUpdate(android.view.View))(container: https://developer.android.com/reference/android/view/View.html)`

**This function is deprecated.**

Use `https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#finishUpdate(android.view.ViewGroup)`

<br />

`abstract https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` `[getCount](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#getCount())()`

**This function is deprecated.** Deprecated in Java
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` `[getItemPosition](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#getItemPosition(java.lang.Object))(object: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)`

**This function is deprecated.** Deprecated in Java
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char-sequence/index.html?` `[getPageTitle](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#getPageTitle(int))(position: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`

**This function is deprecated.** Deprecated in Java
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` `[getPageWidth](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#getPageWidth(int))(position: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`

**This function is deprecated.** Deprecated in Java
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html` `[instantiateItem](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#instantiateItem(android.view.View,int))(container: https://developer.android.com/reference/android/view/View.html, position: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`

**This function is deprecated.**

Use `https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#instantiateItem(android.view.ViewGroup,int)`

<br />

`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `[notifyDataSetChanged](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#notifyDataSetChanged())()`

**This function is deprecated.** Deprecated in Java
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `[registerDataSetObserver](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#registerDataSetObserver(android.database.DataSetObserver))(observer: https://developer.android.com/reference/android/database/DataSetObserver.html)`

**This function is deprecated.** Deprecated in Java
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `[setPrimaryItem](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#setPrimaryItem(android.view.View,int,java.lang.Object))(container: https://developer.android.com/reference/android/view/View.html, position: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, object: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)`

**This function is deprecated.**

Use `https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#setPrimaryItem(android.view.ViewGroup,int,java.lang.Object)`

<br />

`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `[startUpdate](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#startUpdate(android.view.View))(container: https://developer.android.com/reference/android/view/View.html)`

**This function is deprecated.**

Use `https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#startUpdate(android.view.ViewGroup)`

<br />

`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `[unregisterDataSetObserver](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#unregisterDataSetObserver(android.database.DataSetObserver))(observer: https://developer.android.com/reference/android/database/DataSetObserver.html)`

**This function is deprecated.** Deprecated in Java

## Constants

### BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.1.0) Deprecated in [1.3.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.3.0)

```
const val BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT = 1: Int
```

> [!CAUTION]
> **This property is deprecated.**   
> Deprecated in Java

Indicates that only the current fragment will be in the `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State#RESUMED` state. All other Fragments are capped at `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State#STARTED`.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentPagerAdapter#FragmentPagerAdapter(androidx.fragment.app.FragmentManager,int)` |   |

### BEHAVIOR_SET_USER_VISIBLE_HINT

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.1.0) Deprecated in [1.1.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.1.0)

```
const val BEHAVIOR_SET_USER_VISIBLE_HINT = 0: Int
```

> [!CAUTION]
> **This property is deprecated.**   
>
> This behavior relies on the deprecated `https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment#setUserVisibleHint(boolean)` API. Use `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentPagerAdapter#BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT()` to switch to its replacement, `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentTransaction#setMaxLifecycle(androidx.fragment.app.Fragment,androidx.lifecycle.Lifecycle.State)`.

Indicates that `https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment#setUserVisibleHint(boolean)` will be called when the current fragment changes.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentPagerAdapter#FragmentPagerAdapter(androidx.fragment.app.FragmentManager,int)` |   |

## Public constructors

### FragmentPagerAdapter

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.1.0) Deprecated in [1.1.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.1.0)

```
[FragmentPagerAdapter](https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentPagerAdapter#FragmentPagerAdapter(androidx.fragment.app.FragmentManager))(fm: FragmentManager)
```

> [!CAUTION]
> **This function is deprecated.**   
>
> use `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentPagerAdapter#FragmentPagerAdapter(androidx.fragment.app.FragmentManager,int)` with `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentPagerAdapter#BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT()`

Constructor for `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentPagerAdapter` that sets the fragment manager for the adapter. This is the equivalent of calling `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentPagerAdapter#FragmentPagerAdapter(androidx.fragment.app.FragmentManager,int)` and passing in `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentPagerAdapter#BEHAVIOR_SET_USER_VISIBLE_HINT()`.

Fragments will have `https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment#setUserVisibleHint(boolean)` called whenever the current Fragment changes.

| Parameters |
|---|---|
| `fm: https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentManager` | fragment manager that will interact with this adapter |

### FragmentPagerAdapter

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.1.0) Deprecated in [1.3.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.3.0)

```
[FragmentPagerAdapter](https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentPagerAdapter#FragmentPagerAdapter(androidx.fragment.app.FragmentManager,int))(fm: FragmentManager, behavior: Int)
```

> [!CAUTION]
> **This function is deprecated.**   
> Deprecated in Java

Constructor for `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentPagerAdapter`. If `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentPagerAdapter#BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT()` is passed in, then only the current Fragment is in the `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State#RESUMED` state. All other fragments are capped at `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State#STARTED`. If `https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentPagerAdapter#BEHAVIOR_SET_USER_VISIBLE_HINT()` is passed, all fragments are in the `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State#RESUMED` state and there will be callbacks to `https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment#setUserVisibleHint(boolean)`.

| Parameters |
|---|---|
| `fm: https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentManager` | fragment manager that will interact with this adapter |
| `behavior: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | determines if only current fragments are in a resumed state |

## Public functions

### destroyItem

```
fun [destroyItem](https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentPagerAdapter#destroyItem(android.view.ViewGroup,int,java.lang.Object))(container: ViewGroup, position: Int, object: Any): Unit
```

> [!CAUTION]
> **This function is deprecated.**   
> Deprecated in Java

Remove a page for the given position. The adapter is responsible for removing the view from its container, although it only must ensure this is done by the time it returns from `https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#finishUpdate(android.view.ViewGroup)`.

| Parameters |
|---|---|
| `container: https://developer.android.com/reference/android/view/ViewGroup.html` | The containing View from which the page will be removed. |
| `position: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The page position to be removed. |
| `object: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html` | The same object that was returned by `https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#instantiateItem(android.view.View,int)`. |

### finishUpdate

```
fun [finishUpdate](https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentPagerAdapter#finishUpdate(android.view.ViewGroup))(container: ViewGroup): Unit
```

> [!CAUTION]
> **This function is deprecated.**   
> Deprecated in Java

Called when the a change in the shown pages has been completed. At this point you must ensure that all of the pages have actually been added or removed from the container as appropriate.

| Parameters |
|---|---|
| `container: https://developer.android.com/reference/android/view/ViewGroup.html` | The containing View which is displaying this adapter's page views. |

### getItem

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.1.0) Deprecated in [1.3.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.3.0)

```
abstract fun [getItem](https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentPagerAdapter#getItem(int))(position: Int): Fragment
```

> [!CAUTION]
> **This function is deprecated.**   
> Deprecated in Java

Return the Fragment associated with a specified position.

### getItemId

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.1.0) Deprecated in [1.3.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.3.0)

```
fun [getItemId](https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentPagerAdapter#getItemId(int))(position: Int): Long
```

> [!CAUTION]
> **This function is deprecated.**   
> Deprecated in Java

Return a unique identifier for the item at the given position.

The default implementation returns the given position. Subclasses should override this method if the positions of items can change.

| Parameters |
|---|---|
| `position: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Position within this adapter |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | Unique identifier for the item at position |

### instantiateItem

```
fun [instantiateItem](https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentPagerAdapter#instantiateItem(android.view.ViewGroup,int))(container: ViewGroup, position: Int): Any
```

> [!CAUTION]
> **This function is deprecated.**   
> Deprecated in Java

Create the page for the given position. The adapter is responsible for adding the view to the container given here, although it only must ensure this is done by the time it returns from `https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#finishUpdate(android.view.ViewGroup)`.

| Parameters |
|---|---|
| `container: https://developer.android.com/reference/android/view/ViewGroup.html` | The containing View in which the page will be shown. |
| `position: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The page position to be instantiated. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html` | Returns an Object representing the new page. This does not need to be a View, but can be some other container of the page. |

### isViewFromObject

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.1.0) Deprecated in [1.3.0](https://developer.android.com/jetpack/androidx/releases/fragment#1.3.0)

```
fun [isViewFromObject](https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentPagerAdapter#isViewFromObject(android.view.View,java.lang.Object))(view: View, object: Any): Boolean
```

> [!CAUTION]
> **This function is deprecated.**   
> Deprecated in Java

Determines whether a page View is associated with a specific key object as returned by `https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#instantiateItem(android.view.ViewGroup,int)`. This method is required for a PagerAdapter to function properly.

| Parameters |
|---|---|
| `view: https://developer.android.com/reference/android/view/View.html` | Page View to check for association with `object` |
| `object: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html` | Object to check for association with `view` |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | true if `view` is associated with the key object `object` |

### restoreState

```
fun [restoreState](https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentPagerAdapter#restoreState(android.os.Parcelable,java.lang.ClassLoader))(state: Parcelable?, loader: ClassLoader?): Unit
```

> [!CAUTION]
> **This function is deprecated.**   
> Deprecated in Java

Restore any instance state associated with this adapter and its pages that was previously saved by `https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#saveState()`.

| Parameters |
|---|---|
| `state: https://developer.android.com/reference/android/os/Parcelable.html?` | State previously saved by a call to `https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#saveState()` |
| `loader: https://developer.android.com/reference/java/lang/ClassLoader.html?` | A ClassLoader that should be used to instantiate any restored objects |

### saveState

```
fun [saveState](https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentPagerAdapter#saveState())(): Parcelable?
```

> [!CAUTION]
> **This function is deprecated.**   
> Deprecated in Java

Save any instance state associated with this adapter and its pages that should be restored if the current UI state needs to be reconstructed.

| Returns |
|---|---|
| `https://developer.android.com/reference/android/os/Parcelable.html?` | Saved state for this adapter |

### setPrimaryItem

```
fun [setPrimaryItem](https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentPagerAdapter#setPrimaryItem(android.view.ViewGroup,int,java.lang.Object))(container: ViewGroup, position: Int, object: Any): Unit
```

> [!CAUTION]
> **This function is deprecated.**   
> Deprecated in Java

Called to inform the adapter of which item is currently considered to be the "primary", that is the one show to the user as the current page. This method will not be invoked when the adapter contains no items.

| Parameters |
|---|---|
| `container: https://developer.android.com/reference/android/view/ViewGroup.html` | The containing View from which the page will be removed. |
| `position: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The page position that is now the primary. |
| `object: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html` | The same object that was returned by `https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#instantiateItem(android.view.View,int)`. |

### startUpdate

```
fun [startUpdate](https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentPagerAdapter#startUpdate(android.view.ViewGroup))(container: ViewGroup): Unit
```

> [!CAUTION]
> **This function is deprecated.**   
> Deprecated in Java

Called when a change in the shown pages is going to start being made.

| Parameters |
|---|---|
| `container: https://developer.android.com/reference/android/view/ViewGroup.html` | The containing View which is displaying this adapter's page views. |