diff options
Diffstat (limited to 'Xamarin.Forms.Platform.Android')
-rw-r--r-- | Xamarin.Forms.Platform.Android/Renderers/ListViewAdapter.cs | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/Xamarin.Forms.Platform.Android/Renderers/ListViewAdapter.cs b/Xamarin.Forms.Platform.Android/Renderers/ListViewAdapter.cs index 2230d2b4..5dedef6c 100644 --- a/Xamarin.Forms.Platform.Android/Renderers/ListViewAdapter.cs +++ b/Xamarin.Forms.Platform.Android/Renderers/ListViewAdapter.cs @@ -199,7 +199,7 @@ namespace Xamarin.Forms.Platform.Android if (cachingStrategy == ListViewCachingStrategy.RecycleElement && convertView != null) { - var boxedCell = (INativeElementView)convertView; + var boxedCell = convertView as INativeElementView; if (boxedCell == null) { throw new InvalidOperationException($"View for cell must implement {nameof(INativeElementView)} to enable recycling."); @@ -403,20 +403,9 @@ namespace Xamarin.Forms.Platform.Android if (global == position || cells.Count > 0) { - if (_listView.CachingStrategy == ListViewCachingStrategy.RecycleElement) - { - var groupContent = _listView.TemplatedItems.GroupHeaderTemplate?.CreateContent(group.ItemsSource, _listView) as Cell; - if (groupContent != null) - { - groupContent.Parent = _listView; - groupContent.BindingContext = group.ItemsSource; - cells.Add(groupContent); - } - } - else - { - cells.Add(group.HeaderContent); - } + //Always create a new cell if we are using the RecycleElement strategy + var headerCell = _listView.CachingStrategy == ListViewCachingStrategy.RecycleElement ? GetNewGroupHeaderCell(group) : group.HeaderContent; + cells.Add(headerCell); if (cells.Count == take) return cells; @@ -565,6 +554,26 @@ namespace Xamarin.Forms.Platform.Android } } + Cell GetNewGroupHeaderCell(ITemplatedItemsList<Cell> group) + { + var groupHeaderCell = _listView.TemplatedItems.GroupHeaderTemplate?.CreateContent(group.ItemsSource, _listView) as Cell; + + if (groupHeaderCell != null) + { + groupHeaderCell.BindingContext = group.ItemsSource; + } + else + { + groupHeaderCell = new TextCell(); + groupHeaderCell.SetBinding(TextCell.TextProperty, nameof(group.Name)); + groupHeaderCell.BindingContext = group; + } + + groupHeaderCell.Parent = _listView; + groupHeaderCell.SetIsGroupHeader<ItemsView<Cell>, Cell>(true); + return groupHeaderCell; + } + enum CellType { Row, |