Skip to content

Commit 64b887d

Browse files
author
Mattias Flodin
committed
Support for Checkable list items
When ListView has a choiceMode other than none, it can graphically display which item(s) are currently selected, if (and only if) the list items implement the Checkable interface. With DSLV, even if list items implement this interface, it is hidden by the list-item wrapper used (DragSortItemView). With this change, DragSortItemView implements the Checkable interface and forwards it to the wrapped item view if it implements Checkable, allowing DSLV to function properly in all choice modes. I considered a different design where we have a CheckableDragSortItemView that inherits from DragSortItemView. DSLV would then instantiate different variants depending on what is needed. However, the only reason I could find for doing this would be to avoid the few cycles spent on instanceof checks, and the original ListView code does not seem to have any concerns about doing this (see ListView.setupChild).
1 parent 0ad9f5b commit 64b887d

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

library/src/com/mobeta/android/dslv/DragSortItemView.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import android.view.View.MeasureSpec;
77
import android.view.ViewGroup;
88
import android.widget.AbsListView;
9+
import android.widget.Checkable;
910
import android.util.Log;
1011

1112
/**
@@ -23,7 +24,7 @@
2324
* The purpose of this class is to optimize slide
2425
* shuffle animations.
2526
*/
26-
public class DragSortItemView extends ViewGroup {
27+
public class DragSortItemView extends ViewGroup implements Checkable {
2728

2829
private int mGravity = Gravity.TOP;
2930

@@ -97,4 +98,26 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
9798
setMeasuredDimension(width, height);
9899
}
99100

101+
@Override
102+
public boolean isChecked() {
103+
View child = getChildAt(0);
104+
if (child instanceof Checkable)
105+
return ((Checkable) child).isChecked();
106+
else
107+
return false;
108+
}
109+
110+
@Override
111+
public void setChecked(boolean checked) {
112+
View child = getChildAt(0);
113+
if (child instanceof Checkable)
114+
((Checkable) child).setChecked(checked);
115+
}
116+
117+
@Override
118+
public void toggle() {
119+
View child = getChildAt(0);
120+
if (child instanceof Checkable)
121+
((Checkable) child).toggle();
122+
}
100123
}

0 commit comments

Comments
 (0)