From b070e6962f1c5c09b1a6558db0e2f40b2f3be1b3 Mon Sep 17 00:00:00 2001 From: Alex Hart Date: Tue, 21 Sep 2021 10:03:42 -0300 Subject: [PATCH] Remove view from parent before trying to insert into a new container. --- .../securesms/conversation/ConversationAdapter.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationAdapter.java b/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationAdapter.java index 45c45dede9..c521f0ddec 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationAdapter.java +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationAdapter.java @@ -747,6 +747,7 @@ public class ConversationAdapter unbind(); if (view != null) { + removeViewFromParent(view); container.addView(view); } } @@ -754,6 +755,12 @@ public class ConversationAdapter void unbind() { container.removeAllViews(); } + + private void removeViewFromParent(@NonNull View view) { + if (view.getParent() != null) { + ((ViewGroup) view.getParent()).removeView(view); + } + } } private static class PlaceholderViewHolder extends RecyclerView.ViewHolder {