Androidx不兼容的类型:ViewPagerAdapter无法转换为适配器

问题描述 投票:0回答:1

[我正在使用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();
    }
}
java android androidx android-viewpager2
1个回答
0
投票
请参见FragmentStateAdapter以获取更多信息。
© www.soinside.com 2019 - 2024. All rights reserved.