fragmentstatepageradapter

Fragment no longer exists for key FragmentStateAdapter with Viewpager2

一世执手 提交于 2021-02-17 21:54:33
问题 I am using ViewPager2 for my project. I need to use nested fragments inside a fragment with viewpager2. it works like charm until I try to navigate between fragments(not nested ones). After the first time navigating between fragments, the application crash with the error explained below. the fragment which contains nested fragments OnCreateView method: View view = inflater.inflate(R.layout.orders_fragment, null); ViewPager2 viewPager = view.findViewById(R.id.childViewPager); TabLayout tabs =

remove fragment in viewPager2 use FragmentStateAdapter, but still display

北战南征 提交于 2020-04-11 07:41:41
问题 I have a viewPager2 and FragmentStateAdapter, and there are Fragement1, 2,3 4, I am in fragment2, and want to remove fragment3, and display fragment4 after fragment2. The problem is it always show me fragment3(data), the debug shows the fragment3 has been removed, but the displayed page still has fragment3 content. Adpter: class TipsAdapter( private val items: MutableList<TripPage>, context: FragmentActivity ) : FragmentStateAdapter(context) { private val fragmentFactory = context

remove fragment in viewPager2 use FragmentStateAdapter, but still display

依然范特西╮ 提交于 2020-04-11 07:41:32
问题 I have a viewPager2 and FragmentStateAdapter, and there are Fragement1, 2,3 4, I am in fragment2, and want to remove fragment3, and display fragment4 after fragment2. The problem is it always show me fragment3(data), the debug shows the fragment3 has been removed, but the displayed page still has fragment3 content. Adpter: class TipsAdapter( private val items: MutableList<TripPage>, context: FragmentActivity ) : FragmentStateAdapter(context) { private val fragmentFactory = context

FragmentStatePagerAdapter first call to getItem wrong with sdk 22-->23 upgrade

痞子三分冷 提交于 2020-02-02 11:09:47
问题 UPDATE 2: Getting rid of all v4 support references fixed it. UPDATE: I started from scratch to see what triggers this behavior. It occurs once I add a check for location permissions. I can't go backwards -- even when I strip out all the permissions code it stays with the incorrectly-bahaving FragmentStatePagerAdapger. I have a FragementStatePagerAdapter that was working just fine for a ViewPager of dynamically created fragments until I changed my compileSdkVersion and target SdkVersion from

Communication between Fragments in ViewPager

社会主义新天地 提交于 2020-01-09 03:21:27
问题 I'm trying to do this: http://android-er.blogspot.com/2012/06/communication-between-fragments-in.html Except that I'm using a FragmentStatePagerAdapter I have an Activity with two fragments( FragmentA & FragmentB ) FragmentA has an edittext and a button, FragmentB has a textview Now all I want is that whenever I enter something in the edittext and click the button, that something will appear on my textview. MainActivity: public class MainActivity extends FragmentActivity { ViewPager viewPager

How to add a tab to SlidingTabLayout?

落花浮王杯 提交于 2020-01-03 02:29:06
问题 I am using google's SlidingTabLayout in my view, but i want to add dynamically new tabs to it. I'm using this http://developer.android.com/samples/SlidingTabsBasic/src/com.example.android.common/view/SlidingTabLayout.html This is my code which initialize it: // Create the adapter that will return a fragment for each of the three // primary sections of the activity. mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); //this ^ is a FragmentStatePagerAdapter // Set up

Don't restore ViewPager when Activity is restored

萝らか妹 提交于 2020-01-02 12:46:58
问题 The setup of my project is as follows Activity has Fragment and it has ViewPager with pages supplied by FragmentStatePagerAdapter . The data displayed by ViewPager is fetched from network. When Activity is destroyed and restored, it tries to restore the Fragment that was visible in ViewPager when the Activity was destroyed. But the Fragment inside the ViewPager tries to access data structures that are not fully initialized, as a result crash happens. I don't want the Fragment in ViewPager to

ViewPager with different adapters for portrait and landscape

好久不见. 提交于 2020-01-02 03:29:12
问题 In portrait mode, my ViewPager has 3 fragments A, B, C but in landscape mode, it has only 2 fragments A and C. So I create 2 FragmentStatePagerAdapter s for each mode. The problem is when screen orientation changed, ViewPager restores and uses previous fragments of old orientation. For example, when change orientation from portrait to landscape, ViewPager now shows 2 fragments A, B instead of A and C. I know why this happen but can't find a good solution for this. My current workaround is to

how to add page dynamically in FragmentStatePagerAdapter

a 夏天 提交于 2020-01-01 09:38:09
问题 I know this question asked many time but I don't get answered after many research. in my main activity I have a view pager and I set an adapter for that: public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ViewPager mPager; PagerAdapter mPagerAdapter; mPager = (ViewPager) findViewById(R.id.pager); mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager()); mPager.setAdapter(mPagerAdapter); @Override public

offscreen viewpager fragments won't render after 1st time loaded

时光总嘲笑我的痴心妄想 提交于 2019-12-24 23:46:04
问题 I have a viewpager with 5 tabs and if I go to the 5th fragment(that is the fragment loaded when I click the 5th tab or swipe to the 5th tab) and then I go to the 3rd tab the 5th fragment won't load the view anymore and if I go to the 2nd or 1st tab the 4th and 5th tabs won't. I tried changing the viewpager.offscreenlimit(3) or even 5 with no results. If it helps anyone figure it out, it happens regardless of what fragments I put in place of the 3rd 4th and 5th positions. Also, the first