reusing fragments in a fragmentpageradapter

前端 未结 6 547
陌清茗
陌清茗 2020-11-28 02:19

I have a viewpager that pages through fragments. My FragmentPagerAdapter subclass creates a new fragment in the getItem method which seems wasteful

6条回答
  •  迷失自我
    2020-11-28 02:31

    I know this is (theoretically) not an answer to the question, but a different approach.

    I had an issue where I needed to refresh the visible fragments. Whatever I tried, failed and failed miserably...

    After trying so many different things, I have finally finish this using BroadCastReceiver. Simply send a broadcast when you need to do something with the visible fragments and capture it in the fragment.

    If you need some kind of a response as well, you can also send it via broadcast.

    cheers

提交回复
热议问题