本文介绍了当"FragmentManager.PopBackStack()"设置为0时,是否可以将数据返回到先前的片段.叫做?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我正在使用 Xamarin.Android 开发一个应用程序,其中有一个 root 活动,其中包括用于显示不同片段的 frame . root 活动仅包含导航项.整个内容显示在不同的片段中.
片段之一是显示用户列表.我想为此列表提供一个过滤器.因此,我使用所有过滤器选项和一个按钮创建了一个新片段,该按钮应将所有过滤器应用于上一个用户列表片段".
我通过在我的用户列表片段"中添加一个 frame 来显示过滤器"片段,并将过滤器"片段加载到其中:

I'm developing an app with Xamarin.Android in which I have a root activity including a frame for displaying different fragments. The root activity contains only navigation items. The whole content is shown in the different fragments.
One of the fragments is displaying a list of users. I want to provide a filter for this list. So I created a new fragment with all the filter options and a button which should apply all the filters on the previous "User-List-Fragment".
I display the "filter" fragment by adding a frame to my "User-List-Fragment" and load the "filter" fragment into it:

FragmentManager.BeginTransaction()
   .AddToBackStack(null)
   .Replace(Resource.Id.members_filterFrame, new FilterFragment())
   .Commit();

要应用我调用的过滤器

FragmentManager.PopBackStack();

在应用过滤器按钮"的单击事件侦听器"中按

,再次显示用户列表片段".但是,这一切都突然结束了,因为我不知道是否或者如何将筛选器数据填充回我的用户列表片段".

in the "click event listener" of the "apply filter button", to display the "User-List-Fragment" again. But here it all comes to an sudden end because I don't know if or how I can populate the filter data back to my "User-List-Fragment".

这是我的"User-List-Fragment"的 .axml 布局的一部分.< FrameLayout/> 覆盖< ListView/> ,并且仅在用户按下过滤器按钮"时可见.

This is a part of my .axml layout of the "User-List-Fragment". The <FrameLayout /> overlays the <ListView /> and gets only visible if the user presses the "filter button".

    .
    .
    .
<ListView
    android:id="@+id/members_listView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:paddingBottom="150dp" />

<FrameLayout
   android:id="@+id/members_filterFrame"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:visibility="gone" />
    .
    .
    .

问题
调用 FragmentManager.PopBackStack(); 时,是否可以将数据从 FilterFragment 填充回用户列表片段"?
如果可以,怎么办?

Question
Is it possible to populate data from the FilterFragment back to the "User-List-Fragment" when calling FragmentManager.PopBackStack();?
If so, how?

推荐答案

您应该能够将 Action 传递给您的 FilterFragment .

You should be able to pass an Action to your FilterFragment.

调用 OnDestroyView()时,您可以调用 Action 并发送回数据.

When OnDestroyView() is called you can invoke the Action and send back data.

示例

第一个片段

FragmentManager.BeginTransaction()
.AddToBackStack(null)
.Replace(Resource.Id.members_filterFrame, new FilterFragment((parameter) => {
    // Do something with the given parameter
}))
.Commit();

FilterFragment

private Action<T> _onCompletionAction;
public FilterFragment(Action<T> onCompletionAction)
{
    _onCompletionAction = onCompletionAction;
}

public override void OnDestroyView()
{
    base.OnResume();

    _onCompletionAction(parameter) // parameter could be a filter object.
}

这篇关于当"FragmentManager.PopBackStack()"设置为0时,是否可以将数据返回到先前的片段.叫做?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 19:06