是否有可能刷新片段的视图 [英] Is it possible to refresh the view of a Fragment
本文介绍了是否有可能刷新片段的视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我改变了我的应用程序的编程的区域
,像下面这样:
I changed the locale
of my application programmatically, like following:
Resources res = context.getResources();
DisplayMetrics dm = res.getDisplayMetrics();
android.content.res.Configuration conf = res.getConfiguration();
conf.locale = new Locale("cn");
res.updateConfiguration(conf, dm);
在此,我想为刷新我的当前显示片段的视图来显示新的区域设置。
After this, I would like to refresh my currently displayed fragment's view to display with new locale settings.
所以,我首先得到当前片段(这是最新一期的 backstack
):
So, I firstly get the current fragment (that's the latest one in backstack
):
BackStackEntry latestEntry=fragMgr.getBackStackEntryAt(fragMgr.getBackStackEntryCount()-1);
String str=latestEntry.getName();
Fragment fragment=fragMgr.findFragmentByTag(str);
在我得到的目前呈现的片段,我想为刷新的查看,但怎么办呢?是否有可能在Android的刷新片段的视图
After I get the currently showing fragment, I would like to refresh its view, but how to do it? Is it possible in Android to refresh the view of a fragment
推荐答案
您可以简单地分离和附加片段如下
You can simply detach and attach fragment as below
Fragment currentFragment = getFragmentManager().findFragmentByTag("FRAGMENT");
FragmentTransaction fragTransaction = getFragmentManager().beginTransaction();
fragTransaction.detach(currentFragment);
fragTransaction.attach(currentFragment);
fragTransaction.commit();
这将刷新视图和语言环境会改变
This will refresh the view and locale will change
这篇关于是否有可能刷新片段的视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文