Skip to content Skip to sidebar Skip to footer

Can't Scroll In A Listview In A Swiperefreshlayout

I'm having an issue with the SwipeRefreshLayout. I have a list view within the layout and every time I scroll upward in the list view the swipe to refresh layout is tiggered and yo

Solution 1:

I found an answer to my question. I am manually enabling the swipeRefreshLayout when the first child in the listview is at the top of the list.

    listView.setOnScrollListener(newAbsListView.OnScrollListener() {
        @OverridepublicvoidonScrollStateChanged(AbsListView view, int scrollState) {

        }

        @OverridepublicvoidonScroll(AbsListView listView, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            inttopRowVerticalPosition= (listView == null || listView.getChildCount() == 0) ?
                            0 : expandableListview.getChildAt(0).getTop();
            refresh.setEnabled((topRowVerticalPosition >= 0));
        }
    });

Solution 2:

https://developer.android.com/reference/android/support/v4/widget/SwipeRefreshLayout.html

According to Android docs at the above link,

This layout should be made the parent of the view that will be refreshed as a result of the gesture and can only support one direct child.

If the ListView is the 1st direct child of the SwipeRefreshLayout, refresh won't be triggered before scrolling back to the top of the ListView. You don't need to do anything in onScroll().

Post a Comment for "Can't Scroll In A Listview In A Swiperefreshlayout"