以编程方式触发SwipeRefreshLayout

以编程方式触发SwipeRefreshLayout

本文介绍了以编程方式触发SwipeRefreshLayout的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法以编程方式触发 SwipeRefreshLayout ?动画应该开始,并且应该调用 OnRefreshListener 界面中的 onRefresh 方法。

Is there any way to trigger the SwipeRefreshLayout programmatically? The animation should start and the onRefresh method from the OnRefreshListener interface should get called.

推荐答案

如果您使用5.0中的新swipeRefreshLayout

if you are using the new swipeRefreshLayout intoduced in 5.0

如上图所示,您只需添加以下行以编程方式触发滑动刷新布局

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);
        }
    });

如果您只是致电

 mSwipeRefreshLayout.setRefreshing(true);

它不会触发圆形动画,因此通过添加上面的行,你只需要延迟在UI线程中,以便它显示ui线程内的圆形动画。

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.

通过调用 mSwipeRefreshLayout.setRefreshing(true) OnRefreshListener 不会被执行

为了停止循环加载动画调用 mSwipeRefreshLayout.setRefreshing(false)

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

这篇关于以编程方式触发SwipeRefreshLayout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 20:06