When switch fragment with SwipeRefreshLayout during refreshing, fragment freezes but actually still work

后端 未结 8 1914
温柔的废话
温柔的废话 2020-11-28 04:31

UPDATE: I thought it worked correctly. But after some test trouble still exists *sniff*

Then I made a simpler version to see what exactly happen and

8条回答
  •  孤城傲影
    2020-11-28 04:53

    The solution works, but I think it is better just put those lines into its own function, like:

    public void terminateRefreshing() {
        mSwipeRefreshLayout.setRefreshing(false);
        mSwipeRefreshLayout.destroyDrawingCache();
        mSwipeRefreshLayout.clearAnimation();
    }
    

    and call when switching the fragment.

    Fragment prevFrag = fragmentManager.findFragmentById(drawerContainerId);
    
    if(prevFrag instanceof SwipeRefreshFragment) {
        ((SwipeRefreshFragment)prevFrag).terminateRefreshing();
    }
    
    fragmentManager.beginTransaction().replace(drawerContainerId, fragment).commit();
    

提交回复
热议问题