Can't scroll in a ListView in a swipeRefreshLayout
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)); } });
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()
.