Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
138 views
in Technique[技术] by (71.8m points)

java - SwipeRefreshLayout trigger programmatically

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

Work

in Java:

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

on in Kotlin:

mSwipeRefreshLayout.post { mSwipeRefreshLayout.isRefreshing = true }

NOT work

if you simply call in Java:

 mSwipeRefreshLayout.setRefreshing(true);

or in Kotlin

 mSwipeRefreshLayout.isRefreshing = 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)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...