summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.Android
diff options
context:
space:
mode:
authorRui Marinho <me@ruimarinho.net>2016-07-13 09:59:49 +0100
committerGitHub <noreply@github.com>2016-07-13 09:59:49 +0100
commitf7deeece812c9f20f054d239ec3dd6e3700dc254 (patch)
treeb624d76a7ecabb2e0bc4001ec226c7caebcc3e79 /Xamarin.Forms.Platform.Android
parent54e9fe2180e938df87c698a31dfb7fabca83278e (diff)
downloadxamarin-forms-f7deeece812c9f20f054d239ec3dd6e3700dc254.tar.gz
xamarin-forms-f7deeece812c9f20f054d239ec3dd6e3700dc254.tar.bz2
xamarin-forms-f7deeece812c9f20f054d239ec3dd6e3700dc254.zip
[Android] Handle creating a default GroupHeader if no GroupHeaderTemplate is provided (#248)
Diffstat (limited to 'Xamarin.Forms.Platform.Android')
-rw-r--r--Xamarin.Forms.Platform.Android/Renderers/ListViewAdapter.cs39
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,