从调用Activity访问Fragment Element

时间:2017-01-19 17:50:57

标签: c# android xamarin

甚至可以从调用Activity访问Fragment中的Views。或者我必须在调用Bundle时将所有必需的信息放入NewInstance或在我的片段中使用静态方法

protected override void OnCreate(Bundle bundle)
{
    base.OnCreate(bundle);
    SetContentView(Resource.Layout.ActivityNavigationLayout);
    var button = FindViewById<Button>(Resource.Id.Button);
}

private void SetUpFragmentManager()
{
    var frag = OverViewFragment.NewInstance();
    var fm = this.FragmentManager.BeginTransaction();
    fm.Replace(Resource.Id.content_frame, frag);
    fm.Commit();
}

Resource.Id.Button是Fragment在该Activity内部膨胀的一部分时?

public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
    View rootView = inflater.Inflate(Resource.Layout.Main, container, false);
    return rootView;
}

0 个答案:

没有答案