Esempio n. 1
0
            public void OnTabSelected(Android.Support.V7.App.ActionBar.Tab tab, Android.Support.V4.App.FragmentTransaction ft)
            {
                var className = Java.Lang.Class.FromType(fragmentType).Name;

                if (fragment == null)
                {
                    fragment = Fragment.Instantiate(parent, className, args);
                    ft.Add(Android.Resource.Id.Content, fragment, tag);
                }
                else
                {
                    ft.Attach(fragment);
                }

                // TODO: Add AutoTracking here once the autoTracking fixes make it into the SDK.
            }
            private void SetContent(ActionBar.Tab tab, FragmentTransaction ft, int?placeHolder, Activity activity, ActionBar bar)
            {
                if (placeHolder == null)
                {
                    Tracer.Error("The placeholder for tab {0} was not found.", tab);
                    return;
                }
                var layout = activity.FindViewById <ViewGroup>(placeHolder.Value);

                if (layout == null)
                {
                    Tracer.Warn("The ActionBarTabContentId with id = {0} is not found in activity {1}",
                                placeHolder.Value,
                                activity);
                    return;
                }
                if (_content == null)
                {
#if APPCOMPAT
                    _content = tab.GetBindingMemberValue(AttachedMembersCompat.ActionBarTab.Content);
#else
                    _content = tab.GetBindingMemberValue(AttachedMembers.ActionBarTab.Content);
#endif

                    var viewModel = _content as IViewModel;
                    if (viewModel == null)
                    {
                        var fragmentClass = _content as string;
                        //If content is a string, trying to create a fragment.
                        if (!string.IsNullOrEmpty(fragmentClass))
                        {
                            var type = TypeCache <Fragment> .Instance.GetTypeByName(fragmentClass, true, false);

                            if (type != null)
                            {
                                var fragment = Fragment.Instantiate(bar.ThemedContext, Java.Lang.Class.FromType(type).Name);
                                _content = fragment;
                            }
                        }
                        else if (_content is int)
                        {
                            _content = activity.GetBindableLayoutInflater().Inflate((int)_content, null);
                        }
                    }
                    else
                    {
                        viewModel.Settings.Metadata.AddOrUpdate(ViewModelConstants.StateNotNeeded, true);
                    }
                    _content = PlatformExtensions.GetContentView(layout, layout.Context, _content,
                                                                 _contentTemplateProvider.GetTemplateId(), _contentTemplateProvider.GetDataTemplateSelector());
                    if (BindingServiceProvider.BindingManager.GetBindings(tab, AttachedMembers.Object.DataContext).Any())
                    {
                        _content.SetBindingMemberValue(AttachedMembers.Object.Parent, tab);
                    }
                    layout.SetContentView(_content, ft, (@group, fragment, arg3) =>
                    {
                        if (fragment.IsDetached)
                        {
                            arg3.Attach(fragment);
                        }
                        else
                        {
                            arg3.Replace(@group.Id, fragment);
                        }
                    });
                }
                else
                {
                    layout.SetContentView(_content, ft, (@group, fragment, arg3) => arg3.Attach(fragment));
                }
            }