質問

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.

役に立ちましたか?

解決

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

他のヒント

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.

@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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top