刷新片段在重装 [英] refresh fragment at reload

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

问题描述

机器人应用程序,我从装载数据的分贝片段中的表格视图。但是,当我的重新加载片段它显示了previous数据。我可以重新填充的片段与当前的数据,而不是previous数据?

In an android application I'm loading data from a db into a table view inside a fragment. But when I reload the fragment it displays the previous data. Can I repopulate the fragment with current data instead of previous data?

推荐答案

我想你想为刷新片段在DB更新内容

如果是这样,分离的片段,再重新装

If so, detach the fragment and reattach it

// Reload current fragment
Fragment frg = null;
frg = getSupportFragmentManager().findFragmentByTag("Your_Fragment_TAG");
final FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.detach(frg);
ft.attach(frg);
ft.commit();

Your_Fragment_TAG是你给你的片段,当你创建它的名字

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

这code是支持库。

如果你不支持较旧的设备,只需使用 getFragmentManager 而不是 getSupportFragmentManager

If you're not supporting older devices, just use getFragmentManager instead of getSupportFragmentManager

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

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