我是StackFlow的搬运工~
ViewPager嵌套Fragment的时候,Fragment的onResume()和onPause()不能很好的反应出Fragment的可见和不可见.网上也有网友说可以用setUserVisibleHint(boolean isVisibleToUser)方法来解决这个问题.但是~~~今天的这个解决方法有些不同,是以为外国网友提供的.如下:
1) Create LifecycleManager Interface The interface will have two methods and each ViewPager’s Fragment will implement it. These methods Are as follows:
public interface FragmentLifecycle {
public void onPauseFragment();
public void onResumeFragment();
}
2) Let each Fragment implement the interface Add iplements statement for each class declaration:
public class FragmentBlue extends Fragment implements FragmentLifecycle
public class FragmentGreen extends