File tree Expand file tree Collapse file tree 2 files changed +24
-17
lines changed
0301/MyAndroidTutorial/src/net/macdidi/myandroidtutorial
0302/MyAndroidTutorial/src/net/macdidi/myandroidtutorial Expand file tree Collapse file tree 2 files changed +24
-17
lines changed Original file line number Diff line number Diff line change @@ -225,14 +225,17 @@ public void clickMenuItem(MenuItem item) {
225225 @ Override
226226 public void onClick (DialogInterface dialog , int which ) {
227227 // 刪除所有已勾選的項目
228- for (int i = 0 ; i < itemAdapter .getCount (); i ++) {
229- Item item = itemAdapter .get (i );
230-
231- // 如果是勾選的項目就刪除它
232- if (item .isSelected ()) {
233- itemAdapter .remove (item );
234- }
235- }
228+ int index = itemAdapter .getCount () - 1 ;
229+
230+ while (index > -1 ) {
231+ Item item = itemAdapter .get (index );
232+
233+ if (item .isSelected ()) {
234+ itemAdapter .remove (item );
235+ }
236+
237+ index --;
238+ }
236239
237240 // 通知資料改變
238241 itemAdapter .notifyDataSetChanged ();
Original file line number Diff line number Diff line change @@ -187,15 +187,19 @@ public void clickMenuItem(MenuItem item) {
187187 new DialogInterface .OnClickListener () {
188188 @ Override
189189 public void onClick (DialogInterface dialog , int which ) {
190- for (int i = 0 ; i < itemAdapter .getCount (); i ++) {
191- Item item = itemAdapter .get (i );
192-
193- if (item .isSelected ()) {
194- itemAdapter .remove (item );
195- }
196- }
197-
198- itemAdapter .notifyDataSetChanged ();
190+ int index = itemAdapter .getCount () - 1 ;
191+
192+ while (index > -1 ) {
193+ Item item = itemAdapter .get (index );
194+
195+ if (item .isSelected ()) {
196+ itemAdapter .remove (item );
197+ }
198+
199+ index --;
200+ }
201+
202+ itemAdapter .notifyDataSetChanged ();
199203 }
200204 });
201205 d .setNegativeButton (android .R .string .no , null );
You can’t perform that action at this time.
0 commit comments