summaryrefslogtreecommitdiff
path: root/library/main
diff options
context:
space:
mode:
authorMaurice Lam <yukl@google.com>2017-03-28 22:04:40 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2017-03-28 22:04:41 +0000
commit0fa3a152a7486daf0b989d190aa44bb8572bbe1f (patch)
treee22711b3fcc8af24dd2fa0b19b116594ffc3d803 /library/main
parent30fdf76d59d2aa2d28f2b1e4af6d02d6a7c847c7 (diff)
parent4dd5de226fefd5c2fdf040543157357f53ea932e (diff)
downloadsetupwizard-0fa3a152a7486daf0b989d190aa44bb8572bbe1f.tar.gz
Merge "Notify the correct position when removing the last item"
Diffstat (limited to 'library/main')
-rw-r--r--library/main/src/com/android/setupwizardlib/items/ItemGroup.java12
1 files changed, 10 insertions, 2 deletions
diff --git a/library/main/src/com/android/setupwizardlib/items/ItemGroup.java b/library/main/src/com/android/setupwizardlib/items/ItemGroup.java
index d645350..ac643e9 100644
--- a/library/main/src/com/android/setupwizardlib/items/ItemGroup.java
+++ b/library/main/src/com/android/setupwizardlib/items/ItemGroup.java
@@ -193,7 +193,8 @@ public class ItemGroup extends AbstractItemHierarchy implements ItemInflater.Ite
}
/**
- * @return The "Item Position" of the given child, or -1 if the child is empty or not found.
+ * @return The "Item Position" of the given child, or -1 if the child is not found. If the given
+ * child is empty, position of the next visible item is returned.
*/
private int getChildPosition(ItemHierarchy child) {
// Check the identity of the child rather than using .equals(), because here we want
@@ -204,7 +205,14 @@ public class ItemGroup extends AbstractItemHierarchy implements ItemInflater.Ite
private int getChildPosition(int childIndex) {
updateDataIfNeeded();
if (childIndex != -1) {
- return mHierarchyStart.get(childIndex, -1);
+ int childPos = -1;
+ int childCount = mChildren.size();
+ for (int i = childIndex; childPos < 0 && i < childCount; i++) {
+ // Find the position of the first visible child after childIndex. This is required
+ // when removing the last item from a nested ItemGroup.
+ childPos = mHierarchyStart.get(i, -1);
+ }
+ return childPos;
}
return -1;
}