@@ -2499,6 +2499,40 @@ public void moveCheckState(int from, int to) {
2499
2499
}
2500
2500
}
2501
2501
2502
+ /**
2503
+ * Use this when an item has been deleted, to move the check state of all
2504
+ * preceding items up one step. If you have a choiceMode which is not none,
2505
+ * this method must be called when the order of items changes in an
2506
+ * underlying adapter which does not have stable IDs (see
2507
+ * {@link ListAdapter#hasStableIds()}). This is because without IDs, the
2508
+ * ListView has no way of knowing which items have moved where, and cannot
2509
+ * update the check state accordingly.
2510
+ *
2511
+ * See also further comments on {@link #moveCheckState(int, int)}.
2512
+ *
2513
+ * @param position
2514
+ */
2515
+ public void removeCheckState (int position ) {
2516
+ SparseBooleanArray cip = getCheckedItemPositions ();
2517
+
2518
+ if (cip .size () == 0 )
2519
+ return ;
2520
+ int [] runStart = new int [cip .size ()];
2521
+ int [] runEnd = new int [cip .size ()];
2522
+ int rangeStart = position ;
2523
+ int rangeEnd = cip .keyAt (cip .size ()-1 )+1 ;
2524
+ int runCount = buildRunList (cip , rangeStart , rangeEnd , runStart , runEnd );
2525
+ for (int i =0 ; i !=runCount ; i ++) {
2526
+ if (!(runStart [i ] == position || (runEnd [i ] < runStart [i ] && runEnd [i ] > position ))) {
2527
+ // Only set a new check mark in front of this run if it does
2528
+ // not contain the deleted position. If it does, we only need
2529
+ // to make it one check mark shorter at the end.
2530
+ setItemChecked (rotate (runStart [i ], - 1 , rangeStart , rangeEnd ), true );
2531
+ }
2532
+ setItemChecked (rotate (runEnd [i ], - 1 , rangeStart , rangeEnd ), false );
2533
+ }
2534
+ }
2535
+
2502
2536
private static int buildRunList (SparseBooleanArray cip , int rangeStart ,
2503
2537
int rangeEnd , int [] runStart , int [] runEnd ) {
2504
2538
int runCount = 0 ;
0 commit comments