public class BooksActivity extends AppCompatActivity implements SwipeRefreshLayout.OnRefreshListener {
SwipeRefreshLayout swipLayout;
RecyclerView recyclerview;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity);
recyclerview = view.findViewById(R.id.recyclerview);
swipLayout = view.findViewById(R.id.swipe_layout);
swipLayout.setOnRefreshListener(this);
}//end of onCreate
@Override
public void onRefresh() {
//your refresh code here
loadRecyclerViewData()
}
private void loadRecyclerViewData(){
onSuccess(){
//don't forget to stop refreshing
swipLayout.setRefreshing(false);
}
onFaliure(){
//don't forget to stop refreshing
swipLayout.setRefreshing(false);
}
}
}