Exemple #1
0
        public override Android.Views.View GetView(int position, Android.Views.View view, ViewGroup parent)
        {
            var context = BlazorWebViewService.GetCurrentActivity();

            int itemType = GetItemViewType(position);
            int layoutId;

            if (itemType == TYPE_SEPARATOR)
            {
                if (mSeparator == null)
                {
                    mSeparator = new Android.Views.View(context);
                    mSeparator.LayoutParameters = new Android.Widget.ListView.LayoutParams(ViewGroup.LayoutParams.MatchParent, 2, itemType);
                    TypedArray attr = context.ObtainStyledAttributes(
                        new int[] { Android.Resource.Attribute.ListDivider });
                    mSeparator.SetBackgroundResource(attr.GetResourceId(0, 0));
                    attr.Recycle();
                }
                return(mSeparator);
            }
            else if (itemType == TYPE_MENU_ITEM)
            {
                layoutId = Android.Resource.Layout.SimpleListItem1;
            }
            else if (itemType == TYPE_MENU_CHECK)
            {
                layoutId = Android.Resource.Layout.SimpleListItemChecked;
            }
            else if (itemType == TYPE_GROUP)
            {
                layoutId = Android.Resource.Layout.PreferenceCategory;
            }
            else if (itemType == TYPE_SINGLE)
            {
                layoutId = Android.Resource.Layout.SimpleListItemSingleChoice;
            }
            else if (itemType == TYPE_MULTIPLE)
            {
                layoutId = Android.Resource.Layout.SimpleListItemMultipleChoice;
            }
            else
            {
                throw new UnsupportedOperationException();
            }

            if (view == null)
            {
                if (mInflater == null)
                {
                    mInflater = LayoutInflater.From(_builder.Context);
                }
                view = mInflater.Inflate(layoutId, parent, false);
            }

            ModifiableChoice item = GetItem(position);
            TextView         text = (TextView)view;

            text.Enabled = !item.Choice.Disabled;
            text.Text    = item.ModifiableLabel;
            if (view is CheckedTextView)
            {
                bool selected = item.ModifiableSelected;
                if (itemType == TYPE_MULTIPLE)
                {
                    _list.SetItemChecked(position, selected);
                }
                else
                {
                    ((CheckedTextView)view).Checked = selected;
                }
            }
            return(view);
        }