コード例 #1
0
        private void SetIndicator(TabHost.TabSpec tabSpec, object item)
        {
            (item as IViewModel)?.Settings.Metadata.AddOrUpdate(ViewModelConstants.StateNotNeeded, true);
            var templateId = _itemTemplateProvider.GetTemplateId();
            var selector   = _itemTemplateProvider.GetDataTemplateSelector();

            if (templateId == null && selector == null)
            {
                selector = EmptyTemplateSelector.Instance;
            }
            object content = AndroidToolkitExtensions.GetContentView(TabHost, TabHost.Context, item, templateId, selector);

            if (content == EmptyTemplateSelector.EmptyView)
            {
                content = null;
                if (item is IHasDisplayName)
                {
                    BindingServiceProvider.BindingProvider.CreateBindingsFromString(tabSpec, "Title DisplayName", null);
                }
                else
                {
                    tabSpec.SetIndicator(item.ToStringSafe("(null)"));
                }
            }
            var view = content as View;

            if (view == null)
            {
                tabSpec.SetIndicator(content.ToStringSafe("(null)"));
            }
            else
            {
                tabSpec.SetIndicator(view);
            }
        }
コード例 #2
0
 private object GetContent(object item)
 {
     return(AndroidToolkitExtensions.GetContentView(TabHost, TabHost.Context,
                                                    item, _contentTemplateProvider.GetTemplateId(), _contentTemplateProvider.GetDataTemplateSelector()));
 }
コード例 #3
0
 protected virtual Object InstantiateItemInternal(ViewGroup container, object item)
 {
     return((Object)AndroidToolkitExtensions
            .GetContentView(container, container.Context, item, _itemTemplateProvider.GetTemplateId(), _itemTemplateProvider.GetDataTemplateSelector()));
 }
コード例 #4
0
            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 = AndroidToolkitExtensions.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));
                }
            }