[我正在使用ViewPager 2,在viewpager2.setAdapter
上出现以下错误
不兼容的类型:ViewPagerAdapter无法转换为适配器
MainActivty
viewPagerAdapter = new ViewPagerAdapter(getSupportFragmentManager(),fragmentList);
viewPager2.setAdapter(viewPagerAdapter);
ViewPagerAdapter
public class ViewPagerAdapter extends FragmentStatePagerAdapter {
private List<PagerFragment> fragments;
public ViewPagerAdapter(FragmentManager fm, List<PagerFragment> fragments) {
super(fm);
this.fragments = fragments;
}
/* (non-Javadoc)
* @see android.support.v4.app.FragmentPagerAdapter#getItem(int)
*/
@Override
public Fragment getItem(int position) {
return this.fragments.get(position);
}
/* (non-Javadoc)
* @see android.support.v4.view.PagerAdapter#getCount()
*/
@Override
public int getCount() {
return this.fragments.size();
}
}
FragmentStateAdapter
以获取更多信息。