Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 you can never scroll back to the top of the layout. Anyone have any ideas?

like image 298
VirtualProdigy Avatar asked Nov 20 '14 13:11

VirtualProdigy


Video Answer


1 Answers

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(new AbsListView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {

        }

        @Override
        public void onScroll(AbsListView listView, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            int topRowVerticalPosition = (listView == null || listView.getChildCount() == 0) ?
                            0 : expandableListview.getChildAt(0).getTop();
            refresh.setEnabled((topRowVerticalPosition >= 0));
        }
    });
like image 65
VirtualProdigy Avatar answered Oct 20 '22 21:10

VirtualProdigy