Android Open Source - Caldroid Month Pager Adapter






From Project

Back to project page Caldroid.

License

The source code is released under:

MIT License

If you think the Android project Caldroid listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.roomorama.caldroid;
/* w w  w . j a  v a  2s .c  om*/
import java.util.ArrayList;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

/**
 * MonthPagerAdapter holds 4 fragments, which provides fragment for current
 * month, previous month and next month. The extra fragment helps for recycle
 * fragments.
 *
 * @author thomasdao
 */
public class MonthPagerAdapter extends FragmentPagerAdapter {

    private ArrayList<DateGridFragment> fragments;

    // Lazily create the fragments
    public ArrayList<DateGridFragment> getFragments() {
        if (fragments == null) {
            fragments = new ArrayList<DateGridFragment>();
            for (int i = 0; i < getCount(); i++) {
                fragments.add(new DateGridFragment());
            }
        }
        return fragments;
    }

    public void setFragments(ArrayList<DateGridFragment> fragments) {
        this.fragments = fragments;
    }

    public MonthPagerAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public Fragment getItem(int position) {
        DateGridFragment fragment = getFragments().get(position);
        return fragment;
    }

    @Override
    public int getCount() {
        // We need 4 gridviews for previous month, current month and next month,
        // and 1 extra fragment for fragment recycle
        return CaldroidFragment.NUMBER_OF_PAGES;
    }

}




Java Source Code List

com.antonyt.infiniteviewpager.InfinitePagerAdapter.java
com.antonyt.infiniteviewpager.InfiniteViewPager.java
com.caldroidsample.CaldroidSampleActivity.java
com.caldroidsample.CaldroidSampleCustomAdapter.java
com.caldroidsample.CaldroidSampleCustomFragment.java
com.roomorama.caldroid.CaldroidFragment.java
com.roomorama.caldroid.CaldroidGridAdapter.java
com.roomorama.caldroid.CaldroidListener.java
com.roomorama.caldroid.CalendarHelper.java
com.roomorama.caldroid.DateGridFragment.java
com.roomorama.caldroid.MonthPagerAdapter.java
com.roomorama.caldroid.SquareTextView.java
com.roomorama.caldroid.WeekdayArrayAdapter.java