/**
* 通用的FragmentPagerAdapter
* @author xingyimin
*
*/
public class CommonFragmentPagerAdapter extends FragmentPagerAdapter {
private List<Fragment> fragmentLists;
public CommonFragmentPagerAdapter(FragmentManager fm) {
// TODO Auto-generated constructor stub
super(fm);
this.fragmentLists = new ArrayList<Fragment>();
}
public CommonFragmentPagerAdapter(FragmentManager fm, List<Fragment> fragmentLists) {
// TODO Auto-generated constructor stub
super(fm);
this.fragmentLists = fragmentLists;
}
@Override
public Fragment getItem(int arg0) {
// TODO Auto-generated method stub
return null == fragmentLists ? null : fragmentLists.get(arg0);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return null == fragmentLists ? 0 : fragmentLists.size();
}
/**
* 添加单个Fragment
* @param fragmet
*/
public void addFragment(Fragment fragmet){
if (null == fragmentLists) {
return;
}
fragmentLists.add(fragmet);
notifyDataSetChanged();
}
/**
* 添加多个Fragment
* @param lists
*/
public void addragment(List<Fragment> lists){
if (null == fragmentLists) {
return;
}
fragmentLists.addAll(lists);
notifyDataSetChanged();
}
/**
* 清除Fragment后添加单个Fragment
* @param fragmet
*/
public void setFragment(Fragment fragmet){
if (null == fragmentLists) {
return;
}
if (0 != fragmentLists.size()) {
fragmentLists.clear();
}
fragmentLists.add(fragmet);
notifyDataSetChanged();
}
/**
* 清除Fragment后添加多个Fragment
* @param lists
*/
public void setFragment(List<Fragment> lists){
if (null == fragmentLists) {
return;
}
if (0 != fragmentLists.size()) {
fragmentLists.clear();
}
fragmentLists.addAll(lists);
notifyDataSetChanged();
}
/**
* 清空Fragment数据项
*/
public void clear(){
if (null == fragmentLists) {
return;
}
fragmentLists.clear();
notifyDataSetChanged();
}
}
通用的FragmentPagerAdapter
最新推荐文章于 2022-04-08 20:36:29 发布