android fragment 延迟加载数据

public abstract class LazyFragment extends Fragment {
    
    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        if(getUserVisibleHint()) {
            lazyLoad();
        } else {
            onInvisible();
        }
    }
    protected abstract void lazyLoad();
    protected void onInvisible(){}
}

你可能感兴趣的:(安卓--fragment)