Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android] Fix crash removing items in ListView #7411

Merged
merged 1 commit into from May 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Core/src/Handlers/Layout/LayoutHandler.Android.cs
Expand Up @@ -40,7 +40,7 @@ public override void SetVirtualView(IView view)

foreach (var child in VirtualView.OrderByZIndex())
{
PlatformView.AddView(child.ToPlatform(MauiContext));
PlatformView.SafelyAddView(child.ToPlatform(MauiContext));
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/Core/src/Platform/Android/ViewGroupExtensions.cs
Expand Up @@ -6,6 +6,14 @@ namespace Microsoft.Maui.Platform
{
public static class ViewGroupExtensions
{
public static void SafelyAddView(this AViewGroup viewGroup, AView child)
{
if (child.Parent != null)
child.RemoveFromParent();

viewGroup.AddView(child);
}

public static IEnumerable<T> GetChildrenOfType<T>(this AViewGroup viewGroup) where T : AView
{
for (var i = 0; i < viewGroup.ChildCount; i++)
Expand Down