fragment of Caton and refresh problems, lazy loading

Here is mainly about refresh fragment and fragment appeared lazy loading

    If a fragment of this page or more time-consuming, if not using lazy loading slide switch interface will Caton phenomenon, this fragment will first show a blank page will not sideslip card, and then slowly loaded the page content. Such pages do need to load the contents of the operation emerged after the transfer interface, the callback method further fragment appears in two cases

1.viewpager+fragment

2.show,hide fragment

The first:

Callback is

setUserVisibleHint(boolean isVisibleToUser)

The second:

Callback is

onHiddenChanged(boolean hidden)

Here we must distinguish what were doing, there is a problem setUserVisibleHint callback method further fragment created when the page has not loaded the callback will come out, so it is necessary to determine whether the fragment has been created, there is the lazy to do a load operation. Of course also encounter fragment appears to want to click refresh operation data.

in

onActivityCreated中加
activityIsCreated = true;
if (theFragmentIsVisible && !theDelayLoad) {
    theDelayLoad = true;
    delayLoad();
}
@Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        super.setUserVisibleHint(isVisibleToUser);
        if (isVisibleToUser) {
            theFragmentIsVisible = true;
           if (activityIsCreated && !theDelayLoad) {
            theDelayLoad = true;
            delayLoad();//懒加载
           }else if(activityIsCreated){
            onVisibleRefresh();//可见刷新
        } else {
            theFragmentIsVisible = false;
           
        }
    }

I hope everyone has to help

Guess you like

Origin blog.csdn.net/chengzuidongfeng/article/details/90769185
Recommended