@@ -14,11 +14,11 @@ public static enum Mode {
14
14
};
15
15
16
16
private Mode mode = Mode .Single ;
17
-
18
17
public final int INVALID_POSITION = -1 ;
18
+
19
19
private Set <Integer > mOpenPositions = new HashSet <Integer >();
20
20
private int mOpenPosition = INVALID_POSITION ;
21
- private SwipeLayout mPrevious ;
21
+ private Set < SwipeLayout > mShownLayouts = new HashSet < SwipeLayout >() ;
22
22
23
23
/**
24
24
* return the {@link com.daimajia.swipe.SwipeLayout} resource id, int the view item.
@@ -60,6 +60,7 @@ public final View getView(int position, View convertView, ViewGroup parent) {
60
60
swipeLayout .addSwipeListener (swipeMemory );
61
61
swipeLayout .addOnLayoutListener (onLayoutListener );
62
62
swipeLayout .setTag (swipeResourceId , new ValueBox (position , swipeMemory , onLayoutListener ));
63
+ mShownLayouts .add (swipeLayout );
63
64
}
64
65
}else {
65
66
swipeLayout = (SwipeLayout )v .findViewById (swipeResourceId );
@@ -121,6 +122,18 @@ public void closeItem(int position) {
121
122
notifyDataSetChanged ();
122
123
}
123
124
125
+
126
+ public void closeAllItems (){
127
+ closeAllExcept (null );
128
+ }
129
+
130
+ public void closeAllExcept (SwipeLayout layout ){
131
+ for (SwipeLayout s : mShownLayouts ){
132
+ if (s != layout )
133
+ s .close ();
134
+ }
135
+ }
136
+
124
137
class ValueBox {
125
138
OnLayoutListener onLayoutListener ;
126
139
SwipeMemory swipeMemory ;
@@ -174,32 +187,26 @@ class SwipeMemory extends SimpleSwipeListener{
174
187
175
188
@ Override
176
189
public void onClose (SwipeLayout layout ) {
177
- if (mode == Mode .Multiple )
190
+ if (mode == Mode .Multiple ){
178
191
mOpenPositions .remove (position );
179
- else {
180
- if (position == mOpenPosition ) {
181
- mOpenPosition = INVALID_POSITION ;
182
- mPrevious = null ;
183
- }
184
192
}
185
193
}
186
194
187
195
@ Override
188
196
public void onStartOpen (SwipeLayout layout ) {
189
197
if (mode == Mode .Single ) {
190
- if (mOpenPosition != position ){
191
- if (mPrevious != null )
192
- mPrevious .close ();
193
- }
194
- mOpenPosition = position ;
195
- mPrevious = layout ;
198
+ closeAllExcept (layout );
196
199
}
197
200
}
198
201
199
202
@ Override
200
203
public void onOpen (SwipeLayout layout ) {
201
- if (mode == Mode .Multiple )
204
+ if (mode == Mode .Multiple )
202
205
mOpenPositions .add (position );
206
+ else {
207
+ closeAllExcept (layout );
208
+ mOpenPosition = position ;
209
+ }
203
210
}
204
211
205
212
public void setPosition (int position ){
0 commit comments