package com.bwei.adapter; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentPagerAdapter; import java.util.List; /** * Created by 杨柳 on 2018/7/20. */ public class MyAdapter extends FragmentPagerAdapter{ private List<Fragment> list; public MyAdapter(FragmentManager fm, List<Fragment> list) { super(fm); this.list = list; } //几个fragment写几个 private String[] path = {"热点","头条","我的","军事"}; @Override public Fragment getItem(int position) { return list.get(position); } @Override public int getCount() { return list.size(); } @Nullable @Override public CharSequence getPageTitle(int position) { return path[position]; } }
tab(Adapter)
最新推荐文章于 2021-04-23 10:35:20 发布
本文介绍了一个自定义的FragmentPagerAdapter——MyAdapter,该适配器用于管理多个Fragment,并为每个Fragment提供标题。通过继承FragmentPagerAdapter并重写关键方法,实现动态加载Fragment及设置TabLayout的标题。
摘要由CSDN通过智能技术生成