package com.connfa.schedule.view;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.connfa.R;
import com.connfa.schedule.domain.view.SchedulePage;
import com.connfa.schedule.domain.view.Event;

import java.util.Collections;
import java.util.List;

public class ScheduleViewPagerAdapter extends PagerAdapter {

    private final Context context;

    private List<SchedulePage> pages = Collections.emptyList();

    public ScheduleViewPagerAdapter(Context context) {
        this.context = context;
    }

    public void updateWith(List<SchedulePage> pages) {
        this.pages = pages;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return pages.size();
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        SchedulePageView pageView = (SchedulePageView) LayoutInflater.from(context)
                .inflate(R.layout.page_schedule, container, false);

        List<Event> events = pages.get(position).events();
        pageView.updateWith(events);
        container.addView(pageView);

        return pageView;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object view) {
        container.removeView((View) view);
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return pages.get(position).title();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }
}

@@ -64,53 +64,8 @@
 xt;%0A
-import android.support.v4.view.PagerAdapter;%0A
 impo
@@ -214,28 +214,21 @@
 in.view.
-SchedulePage
+Event
 ;%0Aimport
@@ -260,21 +260,81 @@
 in.view.
-Event
+SchedulePage;%0Aimport com.novoda.viewpageradapter.ViewPagerAdapter
 ;%0A%0Aimpor
@@ -428,16 +428,20 @@
 extends 
+View
 PagerAda
@@ -444,16 +444,34 @@
 rAdapter
+%3CSchedulePageView%3E
  %7B%0A%0A    
@@ -884,36 +884,44 @@
    p
-ublic Object instantiateItem
+rotected SchedulePageView createView
 (Vie
@@ -966,35 +966,14 @@
     
-SchedulePageView pageView =
+return
  (Sc
@@ -1089,307 +1089,185 @@
 e);%0A
-%0A
     
+%7D%0A%0A
     
-List%3CEvent%3E events = pages.get(position).events();%0A        pageView.updateWith(events);%0A        container.addView(pageView);%0A%0A        return pageView;%0A    %7D%0A%0A    @Override%0A    public void destroyItem(ViewGroup container, int position, Object view) %7B%0A        container.removeView((View) view
+@Override%0A    protected void bindView(SchedulePageView view, int position) %7B%0A        List%3CEvent%3E events = pages.get(position).events();%0A        view.updateWith(events
 );%0A 

Use ViewPagerAdapter