From a4db58d1a5bf04f509aeeaa17ff6ce7111970e20 Mon Sep 17 00:00:00 2001 From: Jakub Florkowski Date: Sun, 24 Nov 2024 01:57:28 +0100 Subject: [PATCH] [Android] Fixed removing items from grouped list --- .../ListView/Android/ListViewAdapter.cs | 13 +++- .../TestCases.HostApp/Issues/Issue26015.xaml | 58 ++++++++++++++ .../Issues/Issue26015.xaml.cs | 77 +++++++++++++++++++ .../Tests/Issues/Issue26015.cs | 26 +++++++ 4 files changed, 172 insertions(+), 2 deletions(-) create mode 100644 src/Controls/tests/TestCases.HostApp/Issues/Issue26015.xaml create mode 100644 src/Controls/tests/TestCases.HostApp/Issues/Issue26015.xaml.cs create mode 100644 src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue26015.cs diff --git a/src/Controls/src/Core/Compatibility/Handlers/ListView/Android/ListViewAdapter.cs b/src/Controls/src/Core/Compatibility/Handlers/ListView/Android/ListViewAdapter.cs index 630a352ac9ff..9123e806b425 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/ListView/Android/ListViewAdapter.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/ListView/Android/ListViewAdapter.cs @@ -329,6 +329,16 @@ public override AView GetView(int position, AView convertView, ViewGroup parent) return layout; } + bool isHeader = cell.GetIsGroupHeader, Cell>(); + + if (isHeader) + { + // We need to re-render the header to ensure it is properly measured and laid out. + // This is necessary because headers often have different layouts and sizes compared to regular cells, + // and reusing a view for a header can result in incorrect measurements and layout issues. + convertView = null; + } + AView view = CellFactory.GetCell(cell, convertView, parent, _context, _listView); Performance.Start(reference, "AddView"); @@ -337,6 +347,7 @@ public override AView GetView(int position, AView convertView, ViewGroup parent) { if (convertView != view) { + view.RemoveFromParent(); layout.RemoveViewAt(0); layout.AddView(view, 0); } @@ -351,8 +362,6 @@ public override AView GetView(int position, AView convertView, ViewGroup parent) Performance.Stop(reference, "AddView"); - bool isHeader = cell.GetIsGroupHeader, Cell>(); - AView bline; bool isSeparatorVisible = _listView.SeparatorVisibility == SeparatorVisibility.Default; diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue26015.xaml b/src/Controls/tests/TestCases.HostApp/Issues/Issue26015.xaml new file mode 100644 index 000000000000..a47a2758e9fe --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue26015.xaml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + +