如何刷新片段'onResume?' [英] How to refresh fragments 'onResume?'

查看:157
本文介绍了如何刷新片段'onResume?'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从Actvitiy中刷新碎片。 (我们来调用活动A)
活动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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆