infinite ViewPager Pager Adapter android
<p>I have a class that makes LinearLayouts. I'd like to use this class to create LinearLayouts as someone scrolls through each page.</p>

<p>Each layout is the view of a month, so each scroll should show me the next (or previous) month. Ideally, at any given time, there is only 3 months available so that the application does not take up too many resources.</p>

<p>I can't figure out for the life of me how to create a ViewPager / Page Adapter where this would work. Can anyone suggest anything? This is my code so far:</p>

<p>My main Activity:</p>

<pre><code>public class MainActivity extends Activity {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        MyPagerAdapter adapter = new MyPagerAdapter(this);
        ViewPager myPager = (ViewPager) findViewById(R.id.mypanelpager);
        myPager.setAdapter(adapter);
        myPager.setCurrentItem(1);

    } 
</code></pre>

<p>Pager Adapter:</p>

<pre><code> public class MyPagerAdapter extends PagerAdapter {

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

public Object instantiateItem(ViewGroup collection, int position){
    LayoutInflater inflater = (LayoutInflater) collection.getContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

 /* not sure what goes here*/

}
</code></pre>

<p>Here is my Class that creates LinearLayouts. </p>

<pre><code>public class NewMonth {
...
newParentLayout = new LinearLayout(context);
newParentLayout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT));
newParentLayout.setOrientation(LinearLayout.VERTICAL);
...
}
</code></pre>

<p>I was planning on just referencing the linearlayouts with something like:</p>

<pre><code>NewMonth example = new NewMonth(context, 1, 2012);
setContentView(example.newParentLayout);
</code></pre>
