Scroll up does not work with SwipeRefreshLayout in Listview

后端 未结 10 1465
失恋的感觉
失恋的感觉 2020-12-01 10:36

I want to implement scroll to refresh functionality with a listView. Also there are other view elements in the same layout file which are displayed if the list is empty. Her

10条回答
  •  情话喂你
    2020-12-01 11:11

    I had the same problem and solved it:

    listView = (ListView) findViewById(R.id.listView);
    listView.setOnScrollListener(new AbsListView.OnScrollListener() {
        @Override
         public void onScrollStateChanged(AbsListView view, int scrollState) {
    
        }
    
        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            if (listView.getChildAt(0) != null) {
            swipeRefreshLayout.setEnabled(listView.getFirstVisiblePosition() == 0 && listView.getChildAt(0).getTop() == 0);
            }
        }
    });
    

提交回复
热议问题