Additional questions related to the delivery of previous Android fragment values

Asked 2 years ago, Updated 2 years ago, 78 views

Functions that make fragments accessible

public Fragment findFragmentByPosition(int position) {
    return getSupportFragmentManager().findFragmentByTag(
            "android:switcher:" + viewPager.getId() + ":"
                    + + (((FragmentPagerAdapter) viewPager.getAdapter()).getItemId(position)));
}

First of all, thank you Hanloniloni for your previous reply. We have implemented the transfer of values between fragments according to the method you told us before You can get a getItemId (position) only when the adapter uses the FragmentPagerAdapter I'd like to ask you some additional questions.

You must use the FragmentStatePagerAdapter, but even if you try this and that, The app is dying with the exception of referring to the value of you.

It is possible to transfer values between fragments, even if the value changes to the server when the app is running When you move the tab and come back, the information on the screen will be updated in real time It's my purpose to try.

Thank you for reading the long question. Have a good day!

android fragment

2022-09-22 21:50

1 Answers

The code you posted is a kind of trick that can only be used in the FragmentPagerAdapter. If you look at the code below, you can see that the FragmentPagerAdapter generates tags.

Therefore, the above method cannot be used with the FragmentStatePagerAdapter, which does not perform related processing. In the FragmentStatePagerAdapter, use the Map to apply the method of managing fragment instances directly.


2022-09-22 21:50

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.