FragmentPagerAdapter
import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.ViewGroup;
public class PagerAdapter extends FragmentPagerAdapter {
private Context mContext;
public PagerAdapter(FragmentManager manager, Context context) {
super(manager);
this.mContext = context;
}
@Override
public Fragment getItem(int position) {
return PagerEnum.valueOf(position).createFragment();
}
@Override
public int getCount() {
return PagerEnum.values().length;
}
@Override
public CharSequence getPageTitle(int position) {
int stringRes = PagerEnum.valueOf(position).getTitle();
return context.getResources().getString(stringRes);
}
/** Get a Fragment from this Adapter. */
@Override
public Object instantiateItem(ViewGroup container, int position) {
return super.instantiateItem(container, position);
}
}