Heads up! This post was written 10 years ago. Some information might be outdated or may have changed since then.
Using this new layout is pretty easy and this is a standard way to implement common Pull to refresh pattern.
We must know: SwipeRefreshLayout is a ViewGroup layout which can hold only one scrollable view as children.
Example layout file with Swipe Refresh
..............................................
We can set OnRefreshListener to listen when user wants to refresh content
mSwipeLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipe);
mSwipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
System.out.println("Updated");
mSwipeLayout.setRefreshing(false);
}
}); If we want we can use it to display refreshing content before user iteract. For this we can use setRefreshing method
mSwipeLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipe);
mSwipeLayout.post(new Runnable() {
@Override
public void run() {
mSwipeLayout.setRefreshing(true);
}
});