简体   繁体   中英

I cannot call the instantiateItem element in FragmentStateAdapter for viewPager2

When I switched to viewPager2 I had to implement another type of adapter (I used FragmentPagerAdapter and now I use FragmentStateAdapter), now I want to call the instantiateItem element that had the old adapter but it doesn't appear in the new one.

public void onPageChange(int position) {
    //I cannot call instantiateItem from pagerAdapter
    Object object = pagerAdapter.instantiateItem(mMainViewPager,position);
    if (object instanceof MapFragment) {
        MapFragment fragment = (MapFragment) object;
        //fragment.setDevice(mDevice);
        //fragment.setLastTracking();
    }
    if (object instanceof DevicesFragment) {
        DevicesFragment fragment = (DevicesFragment) object;
        //fragment.refresh();
    }
}

我无法达到与 instiateItem 元素具有相同功能的相同方法,尽管许多人在视图寻呼机 2 中尝试过。相反,我创建了接受视图寻呼机片段元素的片段列表。你可以问你在哪里把它们放到这个列表中.当片段状态适配器类调用 createFragment() 方法时,我推入列表。之后,我从宿主片段中使用 get 方法到达

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM