package com.ynzlkj.selfproject.UserMode.adapter;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.ViewGroup;
import java.util.List;
/**
* Created by 陈骏 on 2017/7/14 0014.
* QQ:200622550
* 作用:首页Tab适配
*/
public class TabFragmentPagerAdapter extends FragmentPagerAdapter {
public FragmentManager fm;
private List<Fragment> mFragments;
private List<String> mTitles;
public TabFragmentPagerAdapter(FragmentManager fragmentManager, List<Fragment> fragments) {
super(fragmentManager);
fm = fragmentManager;
mFragments = fragments;
}
public TabFragmentPagerAdapter(FragmentManager fragmentManager, List<Fragment> fragments, List<String> titles) {
super(fragmentManager);
fm = fragmentManager;
mFragments = fragments;
mTitles = titles;
}
// @Override
// public Fragment getItem(int position) {
// return mFragments.get(position);
// }
@Override
public Fragment getItem(int position) {
Fragment fragment = null;
fragment = mFragments.get(position);
Bundle bundle = new Bundle();
bundle.putString("id", "" + position);
fragment.setArguments(bundle);
return fragment;
}
@Override
public int getCount() {
return mFragments.size();
}
@Override
public CharSequence getPageTitle(int position) {
return mTitles != null ? mTitles.get(position) : "";
}
@Override
public Fragment instantiateItem(ViewGroup container, int position) {
Fragment fragment = (Fragment) super.instantiateItem(container,
position);
fm.beginTransaction().show(fragment).commit();
return fragment;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
// super.destroyItem(container, position, object);
Fragment fragment = mFragments.get(position);
fm.beginTransaction().hide(fragment).commit();
}
}
网友评论