a ViewPager which has 3 Fragment(A,B,C),the FragmentA has a SwipeRefreshLayout,for delay-loaded
@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);
}
});
}
- when it refreshing , slide the viewpager to FragmentC ,
- after 3000 return to FragmentA ,
- then refresh the SwipeRefreshLayout, the "000000" and "111111" are overlapped.
But if I use the same code in onCreateView ,not use 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);
}
it will not overlapped, the item is "111111",I think it is the right result. When I slide to FragmentC,the FragmentA will execute onDestroyView.(Does it leak memory in ViewPager?)Why does the old view not destroy when I use SwipeRefreshLayout for delay-loaded?
Sorry for my English.