This blog provide you simple Pull to refresh functionality with SwipeRefreshLayout.
- First of all create new project.
- Open xml layout file and create ListView/ScrollView/Gridview.
Wrap ListView/ScrollView/Gridview with "android.support.v4.widget.SwipeRefreshLayout" like
< android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
< ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent">
< /ListView>
< /android.support.v4.widget.SwipeRefreshLayout>
xml Layout part is finish here. Now open Activity class and initialize SwipeRefreshLayout and ListView.
Set setOnRefreshListener to SwipeRefreshLayout and set refresh functionality in onRefresh() method.
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
refrshAdapter();
}
});
6 . set Color scheme to SwipeToRefresh.
swipeRefreshLayout.setColorSchemeResources(android.R.color.holo_red_light,android.R.color.holo_green_light,android.R.color.holo_purple,android.R.color.holo_blue_light);
7 . Set SetRefreshing false when refresh functionality completed.
swipeRefreshLayout.setRefreshing(false);
Refrences:- SwipeToRefresh
0 Comment(s)