Adapter
public class MonitorPagerAdapter extends FragmentStateAdapter { Context context; List填充fragments = new ArrayList<>(); public MonitorPagerAdapter(FragmentActivity context, List fragments) { super(context); this.context = context; this.fragments = fragments; } @NonNull @Override public Fragment createFragment(int position) { Fragment fragment = fragments.get(position); return fragment; } public Fragment getFragment(int position) { return fragments.get(position); } @Override public int getItemCount() { return fragments.size(); }
var listFragment=ArrayList() listFragment.add(fragment())) listFragment.add(fragment())) mAdapter = MonitorPagerAdapter(mActivity, listFragment) mActivity.binding.vpContent.adapter=mAdapter //禁止滑动 mActivity.binding.vpContent.setUserInputEnabled(false) //设置滑动方向 //mActivity.binding.vpContent.setOrientation(ViewPager2.ORIENTATION_VERTICAL)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)