SwipeRefreshLayout trigger programmatically

前端 未结 7 2145
独厮守ぢ
独厮守ぢ 2020-12-04 16:40

Is there any way to trigger the SwipeRefreshLayout programmatically? The animation should start and the onRefresh method from the OnRefreshLi

7条回答
  •  没有蜡笔的小新
    2020-12-04 16:42

    if you are using the new swipeRefreshLayout intoduced in 5.0 enter image description here

    As the image shown above you just need to add the following line to trigger the swipe refresh layout programmatically

     mSwipeRefreshLayout.post(new Runnable() {
            @Override
            public void run() {
                mSwipeRefreshLayout.setRefreshing(true);
            }
        });
    

    if you simply call

     mSwipeRefreshLayout.setRefreshing(true);
    

    it won't trigger the circle to animate, so by adding the above line u just make a delay in the UI thread so that it shows the circle animation inside the ui thread.

    By calling mSwipeRefreshLayout.setRefreshing(true) the OnRefreshListener will NOT get executed

    In order to stop the circular loading animation call mSwipeRefreshLayout.setRefreshing(false)

提交回复
热议问题