FragmentPagerAdapter with ViewPager and two Fragments. Go to the first from the second and update first's text

前端 未结 3 785
Happy的楠姐
Happy的楠姐 2021-02-06 07:29

I\'m not familiar with FragmentPagerAdapter, so this is going to be one of those questions that we (you) read the description critically.

Structure:

3条回答
  •  面向向阳花
    2021-02-06 07:53

    I searched for a solution to this problem a while myself. Your approach in principle works, but it will break your code if ever the code of the fragment tag creation in the Android base class implementation changes. This is a quite nasty dependency!

    A more elegant approach would be to turn the problem around and keep an instance of your base activity in your fragment. Implement a setter for the tag in your activity and call that inside the fragment upon creation - the tag there is simply available with getTag().

    An example implementation can be found here.

提交回复
热议问题