设置拉刷新清凉在启动或恢复片段 [英] Set pull to refresh as refreshing on start or resume fragment
问题描述
我使用这个库Android的PullToRefresh: https://github.com/chrisbanes/Android-PullToRefresh
我需要实现自动拉刷新上的活动启动,这是有作为拉低片段相同的视觉和功能效果只是触发自动代替用户拉手势。你知道,如果我能做到这一点?
编辑:
我的code是如下
@覆盖
公共查看onCreateView(LayoutInflater吹气,ViewGroup中组,包保存)
{
查看查看= inflater.inflate(R.layout.layout_frg_summarized,组,FALSE);
mPullToRefreshLayout =(PullToRefreshLayout)view.findViewById(R.id.summary_layout);
ActionBarPullToRefresh.from(getActivity())
.allChildrenArePullable()
.listener(本)
.setup(mPullToRefreshLayout); 返回视图。}
@覆盖
公共无效onActivityCreated(捆绑savedInstanceState)
{
super.onActivityCreated(savedInstanceState); //一些code在这里 mPullToRefreshLayout.isRefreshing();}@覆盖
公共无效onResume(){
super.onResume(); 如果(mPullToRefreshLayout.isRefreshing()){
mPullToRefreshLayout.setRefreshing(真);
}}
@覆盖
公共无效的onPause(){
super.onPause();
mPullToRefreshLayout.setRefreshing(假);
如果(mPullToRefreshLayout.isRefreshing()){
mPullToRefreshLayout.setRefreshComplete();
}
}
是的,可以。
类似不必调用的能力 onRefreshComplete()
,有一个 setRefreshing()
方法:
myRefreshableView.setRefreshing();
编辑:
看起来 onRefreshStarted
被称为<一href=\"https://github.com/chrisbanes/ActionBar-PullToRefresh/blob/master/library/src/uk/co/senab/actionbarpulltorefresh/library/listeners/OnRefreshListener.java\">when用户启动的刷新开始。这意味着,如果你想启动从code自己刷新,你必须更新UI并开始刷新自己。我没有看到你的code启动下载,但你一定要好好的该方法的内容到另一种方法,是这样的:
@覆盖
公共无效onRefreshStarted(查看视图){
开始下载();
}
然后,当你想开始在code下载(例如,在 onResume
)
@覆盖
公共无效onResume(){
super.onResume();
mPullToRefreshLayout.setRefreshing(真);
开始下载();
}
您为 isRefreshing()
在 onActivityCreated
调用不起任何作用 - 这是一个检查以确认UI是否是当前在清新的状态或没有。此外,您正在使用在当前 onResume
code,办理入住手续执行调用实际上并没有做任何事情 - 如果布局令人耳目一新,将其设置是令人耳目一新。
I am using this library 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:
myRefreshableView.setRefreshing();
Edit:
It looks like onRefreshStarted
is called when a user-initiated refresh is started. This means if you want to initiate your own refresh from code, you have to update the UI and start the refresh yourself. 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
):
@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. 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.
这篇关于设置拉刷新清凉在启动或恢复片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!