public override View GetView(int position, View convertView, ViewGroup parent) { var wrapperView = (convertView == null) ? new WrapperView(m_Context) : convertView as WrapperView; if (wrapperView == null) { throw new NullReferenceException("Wrapper view can not be null"); } var item = Delegate.GetView(position, wrapperView.Item, wrapperView); View header = null; if (PreviousPositionHasSameHeader(position)) { RecycleHeaderIfExists(wrapperView); } else { header = ConfigureHeader(wrapperView, position); } if ((item is ICheckable) && !(wrapperView is CheckableWrapperView)) { //Need to create Checkable subclass of WrapperView for listview to work correctly wrapperView = new CheckableWrapperView(m_Context); } else if (!(item is ICheckable) && (wrapperView is CheckableWrapperView)) { wrapperView = new WrapperView(m_Context); } wrapperView.Update(item, header, Divider, DividerHeight); return(wrapperView); }
/// <summary> /// Will recycle header from WrapperView if it exists /// </summary> /// <param name="wrapperView">wrapper view where header exists</param> private void RecycleHeaderIfExists(WrapperView wrapperView) { var header = wrapperView.Header; if (header != null) { m_HeaderCache.Add(header); } }
/// <summary> /// Get a header view. This optionally pulls a header from the supplied /// Wrapper view and will also recycle it if it exists /// </summary> /// <param name="wrapperView">Wrapper view to pull header from</param> /// <param name="position">Position of the header</param> /// <returns>New Header view</returns> private View ConfigureHeader(WrapperView wrapperView, int position) { var header = wrapperView.Header ?? PopHeader(); header = Delegate.GetHeaderView(position, header, wrapperView); if (header == null) { throw new NullPointerException("Header view must not be null."); } header.Clickable = true; header.Click += (sender, args) => { if (OnHeaderAdapterClickListener == null) { return; } var headerId = Delegate.GetHeaderId(position); OnHeaderAdapterClickListener.OnHeaderClick((View)sender, position, headerId); }; return(header); }
/// <summary> /// Get a header view. This optionally pulls a header from the supplied /// Wrapper view and will also recycle it if it exists /// </summary> /// <param name="wrapperView">Wrapper view to pull header from</param> /// <param name="position">Position of the header</param> /// <returns>New Header view</returns> private View ConfigureHeader(WrapperView wrapperView, int position) { var header = wrapperView.Header ?? PopHeader(); header = Delegate.GetHeaderView(position, header, wrapperView); if(header == null) throw new NullPointerException("Header view must not be null."); header.Clickable = true; header.Click += (sender, args) => { if (OnHeaderAdapterClickListener == null) return; var headerId = Delegate.GetHeaderId(position); OnHeaderAdapterClickListener.OnHeaderClick((View)sender, position, headerId); }; return header; }
/// <summary> /// Will recycle header from WrapperView if it exists /// </summary> /// <param name="wrapperView">wrapper view where header exists</param> private void RecycleHeaderIfExists(WrapperView wrapperView) { var header = wrapperView.Header; if(header != null) m_HeaderCache.Add(header); }
public override View GetView(int position, View convertView, ViewGroup parent) { var wrapperView = (convertView == null) ? new WrapperView(m_Context) : convertView as WrapperView; if(wrapperView == null) throw new NullReferenceException("Wrapper view can not be null"); var item = Delegate.GetView(position, wrapperView.Item, wrapperView); View header = null; if (PreviousPositionHasSameHeader(position)) { RecycleHeaderIfExists(wrapperView); } else { header = ConfigureHeader(wrapperView, position); } if ((item is ICheckable) && !(wrapperView is CheckableWrapperView)) { //Need to create Checkable subclass of WrapperView for listview to work correctly wrapperView = new CheckableWrapperView(m_Context); } else if (!(item is ICheckable) && (wrapperView is CheckableWrapperView)) { wrapperView = new WrapperView(m_Context); } wrapperView.Update(item, header, Divider, DividerHeight); return wrapperView; }