示例#1
0
        protected override void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }

            _disposed = true;

            if (disposing)
            {
                Controller.ScrollToRequested -= OnScrollToRequested;

                if (_headerRenderer != null)
                {
                    AppCompat.Platform.ClearRenderer(_headerRenderer.View);
                    _headerRenderer.Dispose();
                    _headerRenderer = null;
                }

                _headerView?.Dispose();
                _headerView = null;

                if (_footerRenderer != null)
                {
                    AppCompat.Platform.ClearRenderer(_footerRenderer.View);
                    _footerRenderer.Dispose();
                    _footerRenderer = null;
                }

                _footerView?.Dispose();
                _footerView = null;

                if (Control != null)
                {
                    // Unhook the adapter from the ListView before disposing of it
                    Control.Adapter = null;

                    Control.SetOnScrollListener(null);
                }

                if (_adapter != null)
                {
                    _adapter.Dispose();
                    _adapter = null;
                }
            }

            base.Dispose(disposing);
        }
示例#2
0
        protected override void OnElementChanged(ElementChangedEventArgs <ListView> e)
        {
            base.OnElementChanged(e);

            if (e.OldElement != null)
            {
                ((IListViewController)e.OldElement).ScrollToRequested -= OnScrollToRequested;

                if (Control != null)
                {
                    // Unhook the adapter from the ListView before disposing of it
                    Control.Adapter = null;

                    Control.SetOnScrollListener(null);
                }

                if (_adapter != null)
                {
                    _adapter.Dispose();
                    _adapter = null;
                }
            }

            if (e.NewElement != null)
            {
                AListView nativeListView = Control;
                if (nativeListView == null)
                {
                    var ctx = Context;
                    nativeListView = CreateNativeControl();
                    _refresh       = CreateNativePullToRefresh(ctx);
                    _refresh.SetOnRefreshListener(this);
                    _refresh.AddView(nativeListView, new LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent));
                    SetNativeControl(nativeListView, _refresh);

                    _headerView = new Container(ctx);
                    nativeListView.AddHeaderView(_headerView, null, false);
                    _footerView = new Container(ctx);
                    nativeListView.AddFooterView(_footerView, null, false);
                }

                ((IListViewController)e.NewElement).ScrollToRequested += OnScrollToRequested;
                Control?.SetOnScrollListener(new ListViewScrollDetector(this));

                nativeListView.DividerHeight          = 0;
                nativeListView.Focusable              = false;
                nativeListView.DescendantFocusability = DescendantFocusability.AfterDescendants;
                nativeListView.OnFocusChangeListener  = this;
                nativeListView.Adapter      = _adapter = e.NewElement.IsGroupingEnabled && e.NewElement.OnThisPlatform().IsFastScrollEnabled() ? new GroupedListViewAdapter(Context, nativeListView, e.NewElement) : new ListViewAdapter(Context, nativeListView, e.NewElement);
                _adapter.HeaderView         = _headerView;
                _adapter.FooterView         = _footerView;
                _adapter.IsAttachedToWindow = _isAttached;

                UpdateHeader();
                UpdateFooter();
                UpdateIsSwipeToRefreshEnabled();
                UpdateFastScrollEnabled();
                UpdateSelectionMode();
                UpdateSpinnerColor();
                UpdateHorizontalScrollBarVisibility();
                UpdateVerticalScrollBarVisibility();
            }
        }