Android ViewPager edit

Adding a ViewPager

Make sure the following dependency is added to your app’s build.gradle file under dependencies:

compile ''

Then add the ViewPager to your activity layout:


Then define your PagerAdapter:

public class MyPagerAdapter extends PagerAdapter {

    private Context mContext;

    public CustomPagerAdapter(Context context) {
        mContext = context;

    public Object instantiateItem(ViewGroup collection, int position) {
        // Create the page for the given position. For example:
        LayoutInflater inflater = LayoutInflater.from(mContext);
        ViewGroup layout = (ViewGroup) inflater.inflate(R.layout.xxxx, collection, false);
        return layout;

    public void destroyItem(ViewGroup collection, int position, Object view) {
        // Remove a page for the given position. For example:
        collection.removeView((View) view);

    public int getCount() {
        //Return the number of views available.
        return numberOfPages;

    public boolean isViewFromObject(View view, Object object) {
        // Determines whether a page View is associated with a specific key object
        // as returned by instantiateItem(ViewGroup, int). For example:
        return view == object;

Finally setup the ViewPager in your Activity:

public class MainActivity extends AppCompatActivity {

    protected void onCreate(Bundle savedInstanceState) {

        ViewPager viewPager = (ViewPager) findViewById(;
        viewPager.setAdapter(new MyPagerAdapter(this));

Feedback about page:

Optional: your email if you want me to get back to you:

Table Of Contents
29 ViewPager
64 Menu
112 Loader
119 Xposed
132 Colors
135 Fresco
140 AdMob
147 Button
156 Vk SDK
170 XMPP
176 OpenCV
200 FileIO
203 Moshi
217 Paint
231 AIDL
241 JCodec
243 Okio
255 Looper
  ↑ ↓ to navigate     ↵ to select     Esc to close