简体   繁体   English

将pull设置为刷新为启动或恢复片段时刷新

[英]Set pull to refresh as refreshing on start or resume fragment

I am using this library Android-PullToRefresh: https://github.com/chrisbanes/Android-PullToRefresh 我正在使用这个库Android-PullToRefresh: https//github.com/chrisbanes/Android-PullToRefresh

I need to implement automatic 'pull to refresh' on activity start, that is having the same visual and functional effect as pulling down the fragment just triggered automatically instead of user pull gestures. 我需要在活动开始时实现自动“拉动刷新”,即具有与拉下自动触发的片段而不是用户拉动手势相同的视觉和功能效果。 Do you know if I can do this ? 你知道我能做到吗?

EDIT: My code is as below 编辑:我的代码如下

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup group, Bundle saved)
{
    View view = inflater.inflate(R.layout.layout_frg_summarized, group, false);
    mPullToRefreshLayout = (PullToRefreshLayout) view.findViewById(R.id.summary_layout);
    ActionBarPullToRefresh.from(getActivity())
    .allChildrenArePullable()
    .listener(this)
    .setup(mPullToRefreshLayout);   

    return view;

}


@Override
public void onActivityCreated (Bundle savedInstanceState)
{
    super.onActivityCreated(savedInstanceState);

    //some code here

    mPullToRefreshLayout.isRefreshing();

}

@Override
public void onResume(){
    super.onResume();

    if (mPullToRefreshLayout.isRefreshing()) {
     mPullToRefreshLayout.setRefreshing(true);
    } 

}


@Override
public void onPause(){
    super.onPause();
    mPullToRefreshLayout.setRefreshing(false);
    if (mPullToRefreshLayout.isRefreshing()) {
        mPullToRefreshLayout.setRefreshComplete();
    } 


}

Yes, you can. 是的你可以。

Similar to having the ability to call onRefreshComplete() , there is a setRefreshing() method: 与能够调用onRefreshComplete()类似,有一个setRefreshing()方法:

myRefreshableView.setRefreshing();

Edit: 编辑:

It looks like onRefreshStarted is called when a user-initiated refresh is started . 看起来在启动用户启动的刷新时调用onRefreshStarted This means if you want to initiate your own refresh from code, you have to update the UI and start the refresh yourself. 这意味着如果要从代码启动自己的刷新,则必须更新UI并自行开始刷新。 I don't see your code for starting the download, but you'd have to pull the contents of that method out to another method, something like this: 我没有看到你的代码开始下载,但你必须将该方法的内容拉出到另一个方法,如下所示:

@Override
public void onRefreshStarted(View view) {
    startDownload();
}

Then, when you want to start a download in code (for example in onResume ): 然后,当您想要在代码中开始下载时(例如在onResume ):

@Override
public void onResume(){
    super.onResume();
    mPullToRefreshLayout.setRefreshing(true);
    startDownload();
}

Your call to isRefreshing() in onActivityCreated does nothing - that's a check to confirm whether the UI is currently in 'refreshing' state or not. 您对onActivityCreated中的isRefreshing()调用不执行任何操作 - 这是检查UI是否当前处于“刷新”状态。 Additionally, you're using that check in your current onResume code to perform a call that doesn't actually do anything - if the layout is refreshing, you set it to be refreshing. 此外,您在当前的onResume代码中使用该检查来执行实际上不执行任何操作的调用 - 如果布局是刷新的,则将其设置为刷新。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM