How to determine when Fragment becomes visible in ViewPager

后端 未结 26 1318
心在旅途
心在旅途 2020-11-22 00:24

Problem: Fragment onResume() in ViewPager is fired before the fragment becomes actually visible.

For example, I have 2 fragments with

26条回答
  •  被撕碎了的回忆
    2020-11-22 01:06

    I figured out that onCreateOptionsMenu and onPrepareOptionsMenu methods called only in the case of the fragment really visible. I could not found any method which behaves like these, also I tried OnPageChangeListener but it did not work for the situations, for example, I need a variable initialized in onCreate method.

    So these two methods can be used for this problem as a workaround, specifically for little and short jobs.

    I think, this is the better solution but not the best. I will use this but wait for better solution at the same time.

    Regards.

提交回复
热议问题