在活动中重新启动片段 [英] Restart fragment inside activity

查看:181
本文介绍了在活动中重新启动片段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个疑问。



我有一个活动,里面有3个片段。我需要重新启动这些片段之一的状态。 仅重新启动一个



解决方案

旧的,但可能对其他人有用。要刷新片段,您需要分离片段并重新附加片段。

 片段frg = null; 
frg = getFragmentManager()。findFragmentByTag(Your_Fragment_TAG);
final FragmentTransaction ft = getFragmentManager()。beginTransaction();
ft.detach(frg);
ft.attach(frg);
ft.commit();

Your_Fragment_TAG 是您创建片段时所用的名称 p>

I have a litle doubt.

I have an activity that have 3 fragment inside. I need to restart the state of one of these fragments. Restart only one.

解决方案

Old, but may be useful to someone else. To refresh the fragment, you need to detach the fragment and reattach it

Fragment frg = null;
frg = getFragmentManager().findFragmentByTag("Your_Fragment_TAG");
final FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.detach(frg);
ft.attach(frg);
ft.commit();

Your_Fragment_TAG is the name you gave your fragment when you created it

这篇关于在活动中重新启动片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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