为什么viewpager中的swipeRefreshLayout导致重叠?

时间:2015-11-20 09:28:57

标签: android android-viewpager swiperefreshlayout

一个ViewPager有3个片段(A,B,C),FragmentA有一个SwipeRefreshLayout,用于延迟加载

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {

    swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
           new Handler().postDelayed(new Runnable() {
               @Override
               public void run() {
                   //before refresh the item is "000000"
                   //change Data and notify
                   //after is "111111"
                   adapter.update(data);
               }
           },3000);
        }
    });
}
  1. 刷新时,将viewpager滑动到FragmentC,
  2. 3000回到FragmentA后,
  3. 然后刷新SwipeRefreshLayout,“000000”和“111111” 重叠
  4. 但如果我在onCreateView中使用相同的代码,请不要使用SwipeRefreshLayout

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        //……
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                //before refresh the item is "000000"
                //change Data and notify
                //after is "111111"
                adapter.update(data);
            }
        }, 3000);
    }
    

    不重叠 ,项目为“111111”,我认为这是正确的结果。 当我滑到FragmentC时,FragmentA将执行onDestroyView。(它是否会泄漏ViewPager中的内存?)当我使用SwipeRefreshLayout进行延迟加载时,为什么旧​​视图不会破坏

    enter image description here

    抱歉我的英文。

0 个答案:

没有答案