如何刷新片段'onResume?' [英] How to refresh fragments 'onResume?'
问题描述
活动A包含片段。
当我完成活动B时,活动A应刷新片段。
我以为这会在onResume中完成?我尝试通过意图重新启动活动,但这不是友好的可用性。
那么当我恢复活动时如何刷新片段?
只需将此代码放在
onResume()
例如,你想在你返回你的分数时更新你的列表视图。
@Override
public void onResume(){
super.onResume();
if(allowRefresh)
{
allowRefresh = false;
lst_applist = db.load_apps();
getFragmentManager()。beginTransaction()。detach(this).attach(this).commit();
}
}
这里 getFragmentManager()。beginTransaction() .detach(this).attach(this).commit();
此行分离并重新附加片段,以便您的内容将被更新。
I want to refresh fragments from an Actvitiy. (Let's call the activity A) Activity A contains the fragments.
When I finish Activity B then Activity A should refresh the fragments.
I was thinking this would be done in onResume? I tried simply restarting the activity through an intent but that's not usability friendly.
So how do I refresh fragments when I resume an activity?
Just put this code inside
onResume()
For example you want to update your listview when u return to your fregment.
@Override
public void onResume() {
super.onResume();
if (allowRefresh)
{
allowRefresh = false;
lst_applist = db.load_apps();
getFragmentManager().beginTransaction().detach(this).attach(this).commit();
}
}
Here getFragmentManager().beginTransaction().detach(this).attach(this).commit();
This line detach and re-attach the fragment so your content will be updated.
这篇关于如何刷新片段'onResume?'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!