Update a TextView in a ViewPager from another Fragment

前端 未结 4 1745
有刺的猬
有刺的猬 2021-01-07 17:23

I am trying to update a TextView in a Fragment clicking on a button on another Fragment.

Actually I implemented the callback function to the Activity and it does wor

4条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-07 18:01

    I assume the Fragments you are seeing on screen are not the Fragments you manually add with the tags "FirstFragment" and "SecondFragment" but instead the fragments that are added by the getItem method of your TabsAdapter.

    If you look at its implementation, it instantiates new Fragments.

        @Override
        public Fragment getItem(int position) {
            return Fragment.instantiate(mContext, mTabs.get(position), null);
        }
    

    These newly created Fragments are added to the FragmentManager with custom tags generated in FragmentPagerAdapter (which TabsAdapter extends)

提交回复
热议问题