From 311159d5fa328b37877560c8ac7435172af56188 Mon Sep 17 00:00:00 2001 From: tehcneko <7764726+tehcneko@users.noreply.github.com> Date: Sat, 20 Mar 2021 21:23:58 +0800 Subject: [PATCH] Fix checked status --- .../hippo/easyrecyclerview/EasyRecyclerView.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/hippo/easyrecyclerview/EasyRecyclerView.java b/app/src/main/java/com/hippo/easyrecyclerview/EasyRecyclerView.java index 081644cb5..c8f905338 100644 --- a/app/src/main/java/com/hippo/easyrecyclerview/EasyRecyclerView.java +++ b/app/src/main/java/com/hippo/easyrecyclerview/EasyRecyclerView.java @@ -119,7 +119,7 @@ public class EasyRecyclerView extends ScrollLessRecyclerView { */ private LongSparseArray mCheckedIdStates; - private Adapter mAdapter; + private Adapter mAdapter; public EasyRecyclerView(Context context) { super(context); @@ -161,6 +161,18 @@ public class EasyRecyclerView extends ScrollLessRecyclerView { } } + @Override + public void onChildAttachedToWindow(@NonNull View child) { + super.onChildAttachedToWindow(child); + + if (mCheckStates != null) { + int position = getChildAdapterPosition(child); + if (position >= 0) { + setViewChecked(child, mCheckStates.get(position)); + } + } + } + /** * Returns the number of items currently selected. This will only be valid * if the choice mode is not {@link #CHOICE_MODE_NONE} (default).