Android setUserVisibleHint never gets called?

前端 未结 2 1641
無奈伤痛
無奈伤痛 2020-12-31 04:47

I need to know when my fragment is visible, I was using setMenuVisibility but I now know it\'s not a good option. I\'m trying to implement setUserVisibleHint on a FragmentSt

相关标签:
2条回答
  • 2020-12-31 05:31
    setUserVisibleHint() 
    

    only works in a FragmentPagerAdapter. Please refer to Is Fragment.setUserVisibleHint() called by the android System?

    0 讨论(0)
  • 2020-12-31 05:32

    setUserVisibleHint is available so that you have a way to tell the system the fragment is in fact not visible and not the other way around, when you are doing some fancy fragment transactions that specifically hide it. You can't use it to determine visibility and it defaults to true.

    You should use the isVisible call to know if the fragment is visible and onAttach of the fragment or the root view classes to get callbacks when it's been attached to the activity or the respective root views.

    0 讨论(0)
提交回复
热议问题