一个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);
}
});
}
但如果我在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进行延迟加载时,为什么旧视图不会破坏 ?
抱歉我的英文。