Java tutorial
/* * Copyright (C) 2012 www.amsoft.cn * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.sunshine.adapterlibrary.adapter; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.view.ViewPager; import android.view.View; import java.util.List; /** * 2012 amsoft.cn ??AbFragmentPagerAdapter.java ??Fragment? * * @author * @version v1.0 * @date2013-11-28 ?10:57:53 */ public class FragmentAdapter extends FragmentPagerAdapter { /** The m fragment list. */ private List<Fragment> mFragmentList = null; /** * Instantiates a new ab fragment pager adapter. * * @param mFragmentManager * the m fragment manager * @param mFragments * the fragment list */ public FragmentAdapter(FragmentManager mFragmentManager, List<Fragment> mFragments) { super(mFragmentManager); mFragmentList = mFragments; } /** * ????. * * @return the count * @see android.support.v4.view.PagerAdapter#getCount() */ @Override public int getCount() { return mFragmentList.size(); } /** * ????Fragment. * * @param position * the position * @return the item * @see FragmentPagerAdapter#getItem(int) */ @Override public Fragment getItem(int position) { Fragment fragment = null; if (position < mFragmentList.size()) { fragment = mFragmentList.get(position); } else { fragment = mFragmentList.get(0); } return fragment; } /** * ??View. * * @param container the container * @param position the position * @return the object * @see android.support.v4.view.PagerAdapter#instantiateItem(View, int) */ @Override public Fragment instantiateItem(View container, int position) { Fragment v = mFragmentList.get(position); return v; } /** * ??View. * * @param container the container * @param position the position * @param object the object * @see android.support.v4.view.PagerAdapter#destroyItem(View, int, Object) */ @Override public void destroyItem(View container, int position, Object object) { ((ViewPager) container).removeView((View) object); } }