From 3fc320dbef39d6a8658e86f4582ada850a27c10d Mon Sep 17 00:00:00 2001 From: wangzhichao Date: Thu, 24 Sep 2020 16:22:09 +0800 Subject: [PATCH 1/2] add transient keyword for unserialized member of Callback class. --- .../src/main/java/com/kingja/loadsir/callback/Callback.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/loadsir/src/main/java/com/kingja/loadsir/callback/Callback.java b/loadsir/src/main/java/com/kingja/loadsir/callback/Callback.java index f049e13..9952ed4 100644 --- a/loadsir/src/main/java/com/kingja/loadsir/callback/Callback.java +++ b/loadsir/src/main/java/com/kingja/loadsir/callback/Callback.java @@ -17,8 +17,8 @@ * Email:kingjavip@gmail.com */ public abstract class Callback implements Serializable { - private View rootView; - private Context context; + private transient View rootView; + private transient Context context; private OnReloadListener onReloadListener; private boolean successViewVisible; From 30d8f8ce450b0039afcc190e425d8c2599e54479 Mon Sep 17 00:00:00 2001 From: wangzhichao Date: Fri, 25 Sep 2020 15:38:49 +0800 Subject: [PATCH 2/2] ViewTarget:use indexOfChild() method to find childIndex. --- .../main/java/com/kingja/loadsir/target/ViewTarget.java | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/loadsir/src/main/java/com/kingja/loadsir/target/ViewTarget.java b/loadsir/src/main/java/com/kingja/loadsir/target/ViewTarget.java index 8b8a6b0..395dbc0 100644 --- a/loadsir/src/main/java/com/kingja/loadsir/target/ViewTarget.java +++ b/loadsir/src/main/java/com/kingja/loadsir/target/ViewTarget.java @@ -27,14 +27,8 @@ public LoadLayout replaceView(Object target, Callback.OnReloadListener onReloadL View oldContent = (android.view.View) target; ViewGroup contentParent = (ViewGroup) (oldContent.getParent()); int childIndex = 0; - int childCount = contentParent == null ? 0 : contentParent.getChildCount(); - for (int i = 0; i < childCount; i++) { - if (contentParent.getChildAt(i) == oldContent) { - childIndex = i; - break; - } - } if (contentParent != null) { + childIndex = contentParent.indexOfChild(oldContent); contentParent.removeView(oldContent); } ViewGroup.LayoutParams oldLayoutParams = oldContent.getLayoutParams();