3

Im using Chris Banes ActionBar-PullToRefresh. I can start refreshing by pulling the layout down - everything is fine.

But how can i programmatically force start refreshing animation (progress animation)? Or how can i force start full refreshing programmatically like if i pull the layout down?

Tried:

mPullToRefreshLayout.startLayoutAnimation();
mPullToRefreshLayout.setRefreshing(true);
mPullToRefreshLayout.setActivated(true);

Nothing worked.

The only thing i got to work is check for isRefreshing and stop it:

if(mPullToRefreshLayout.isRefreshing()){
   mPullToRefreshLayout.setRefreshComplete();
}

Please help.

localhost
  • 5,568
  • 1
  • 33
  • 53
  • possible duplicate of [Set pull to refresh as refreshing on start or resume fragment](http://stackoverflow.com/questions/21006851/set-pull-to-refresh-as-refreshing-on-start-or-resume-fragment) – Adam S Feb 21 '14 at 10:30
  • `setRefreshing(true)` should start the view animating, but _won't_ call the `onRefreshStarted` callback, you have to call that yourself when you start the refresh animation manually. – Adam S Feb 21 '14 at 10:31
  • Nop. setRefreshing(true) doesn't work as i said in topic :( – localhost Feb 21 '14 at 10:37

3 Answers3

3

Usually mPullToRefreshLayout.setRefreshing(true); is working (if getWindow().getWindowToken != null). If that's not working , you can see my fork https://github.com/quxey/ActionBar-PullToRefresh

Edited . Try this

final ViewGroup decorView = (ViewGroup)getActivity().getWindow().getDecorView();
                    if(decorView.getWindowToken() == null){
                    decorView.post(new Runnable() {
                                @Override
                                public void run() {
                                    if (decorView.getWindowToken() != null) {
                                        mPullToRefreshLayout.setRefreshing(true);
                                    } else {
                                        decorView.post(this);
                                    }
                                }
                            });
                    }else{
                    mPullToRefreshLayout.setRefreshing(true);
                    }
Ramz
  • 7,116
  • 6
  • 63
  • 88
dooplaye
  • 999
  • 13
  • 28
  • I know that should work, but it doesn't. Seems something is wrong in my app, as temporary measure i've done a progress bar on initial refresh like in GMail. Will look into it in future to fix:) – localhost Feb 26 '14 at 05:41
0

I briefly looked through the library code and find out where could be problem with listener.

    if (fromTouch) {
        if (mOnRefreshListener != null) {
            mOnRefreshListener.onRefreshStarted(view);
        }
    }

This part of code from a method startRefresh(View view, boolean fromTouch). Param fromTouch points who was refresh initiator. If you start your pulltorefresh without any touch, fromTouch is set false so mOnRefreshListener.onRefreshStarted(view); is not triggered. I conclude that the method is called only on pull touches. You can check this by yourself maybe your problem was the same.

validcat
  • 6,158
  • 2
  • 29
  • 38
0

@AdamS made it simple here. A one liner myRefreshableView.setRefreshing(); I placed it in my fragment's onResume(). Works except that since I'm doing this programmatically, I would love to have the refresh without the pull-to-refresh bounce.

Community
  • 1
  • 1
Senti
  • 309
  • 2
  • 13