c# - 在两个片段

时间:2017-06-19 17:25:59

标签: c# android android-fragments xamarin.android

我试图将fragmentA中的数据导入我的另一个片段,即fragmentB。在我的fragmentA中有一个Edittext字段,当用户点击提交按钮时,来自Edittext的数据应显示在我的fragmentB中。我试图关注this link,但由于我是xamarin mobile dev领域的新手,我无法找到答案。任何人都可以帮我解决这个问题。

我试过这样做,但我没有从fragmentA到fragmentB的任何数据 fragmentA

submitButton.Click += delegate
        {
            TrackInfoFragment fragment = new TrackInfoFragment();
            Bundle bundle = new Bundle();
            bundle.PutString("message", "From Activity");
            fragment.Arguments = bundle;
        };

fragmentB

Bundle bundle = new Bundle();
        string test = bundle.GetString("message");
        Console.WriteLine("Test: " + test);

1 个答案:

答案 0 :(得分:0)

您正在实例化一个新捆绑包。 在fragmentB上,从Arguments获取数据。

而不是:

Bundle bundle = new Bundle();
string test = bundle.GetString("message");
Console.WriteLine("Test: " + test);

尝试

string test = Arguments.GetString("message");
Console.WriteLine("Test: " + test);

希望它有所帮助...

资料来源:Xamarin Android passing variable from Activity to Fragment returns null

相关问题