MvxCachingFragmentCompatActivity刷新缓存的片段 [英] MvxCachingFragmentCompatActivity refresh cached fragment
问题描述
我有一个基于 XPlatformMenus MvvmCross示例的项目.该应用程序正在使用一个从MvxCachingFragmentCompatActivity
继承的活动.该应用程序使用NavigationView
滑动抽屉允许导航到在运行时换出的不同片段.
I have a project based off the XPlatformMenus MvvmCross sample. The app is using one activity inherited from MvxCachingFragmentCompatActivity
. The app uses a NavigationView
sliding drawer to allow navigation to different fragments that are swapped out at runtime.
我有一个片段,其中显示了使用RecyclerView
的列表.我可以向下滚动到列表的底部,单击后退"按钮,然后从导航菜单中再次调用该片段,然后该片段的显示将完全一样(滚动位置位于列表的底部).如何使它始终像我在调用ShowViewModel<TViewModel>
之后第一次创建该片段一样开始?我想我不希望缓存此特定片段,或者当片段再次显示时,我想让某种事件挂接到我以重置ViewModel.该问题如何解决?
I have one fragment which displays a list using RecyclerView
. I can scroll down to the bottom of the list, hit the back button, then invoke the fragment again from the navigation menu, and the fragment is displayed exactly as it was (with the scrolled position at the bottom of the list). How can I make it so the fragment always starts as if it was created for the first time after I call ShowViewModel<TViewModel>
? I think I don't want this specific fragment to be cached, or I want to have some kind of event I can hook into to reset the ViewModel when the fragment is being displayed again. How can this problem be solved?
推荐答案
I have not tested this yet, but looking at MvxCachingFragmentCompatActivity there seems to be virtual method you can override
protected override void ShowFragment(
string tag,
int contentId,
Bundle bundle,
bool forceAddToBackStack = false,
bool forceReplaceFragment = false)
forceReplaceFragment
参数的注释为:
如果要重新创建片段.
If you want the fragment to be re-created.
也许像这样:
protected override void ShowFragment(
string tag,
int contentId,
Bundle bundle,
bool forceAddToBackStack = false,
bool forceReplaceFragment = false)
{
if (tag.Equals(typeof(<<VIEW_MODEL_TYPE>>).FullName))
forceReplaceFragment = true;
base.ShowFragment(tag, contentId, bundle, forceAddToBackStack, forceReplaceFragment);
}
这篇关于MvxCachingFragmentCompatActivity刷新缓存的片段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!