Search code examples
javaandroidandroid-fragmentsswiperefreshlayout

How to disable back press when Swipe to layout is Refreshing layout in Fragment


Im getting problem with swipe to refresh layout, if swipe for refresh my layout on that time if I pressed back button it close all activity's and fragments.. i checked log but there no Application Terminated error...


Solution

  • You can use isRefreshing()

    Whether the SwipeRefreshWidget is actively showing refresh progress.

    Sample code

    @Override
        public void onBackPressed() {
            if (swipeRefreshLayout.isRefreshing()){
               //  swipeRefreshLayout is Refreshing
            }else {
               //  swipeRefreshLayout is not Refreshing call super.onBackPressed();
               super.onBackPressed();
            }
        }