简体   繁体   English

我无法为 viewPager2 调用 FragmentStateAdapter 中的 instantiateItem 元素

[英]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.当我切换到 viewPager2 时,我必须实现另一种类型的适配器(我使用了 FragmentPagerAdapter,现在我使用 FragmentStateAdapter),现在我想调用具有旧适配器但它没有出现在新适配器中的 instantiateItem 元素。

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 方法到达

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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