java.lang.Object | ||||||
↳ | android.view.View | |||||
↳ | android.view.ViewGroup | |||||
↳ | android.widget.AdapterView<T extends android.widget.Adapter> | |||||
↳ | android.widget.AbsListView | |||||
↳ | android.widget.ListView | |||||
↳ | com.mobeta.android.dslv.DragSortListView |
ListView subclass that mediates drag and drop resorting of items.
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
DragSortListView.DragListener | |||||||||||
DragSortListView.DragScrollProfile | Interface for controlling scroll speed as a function of touch position and time. | ||||||||||
DragSortListView.DragSortListener | |||||||||||
DragSortListView.DropListener | Your implementation of this has to reorder your ListAdapter!
Make sure to call
notifyDataSetChanged() or something like it
in your implementation. |
||||||||||
DragSortListView.FloatViewManager | Interface for customization of the floating View appearance and dragging behavior. | ||||||||||
DragSortListView.RemoveListener | Make sure to call
notifyDataSetChanged() or something like it
in your implementation. |
Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
int | DRAG_NEG_X | Drag flag bit. | |||||||||
int | DRAG_NEG_Y | Drag flag bit. | |||||||||
int | DRAG_POS_X | Drag flag bit. | |||||||||
int | DRAG_POS_Y | Drag flag bit. |
[Expand]
Inherited Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() |
[Expand]
Inherited Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Cancel a drag.
| |||||||||||
As opposed to
getAdapter() , which returns
a heavily wrapped ListAdapter (DragSortListView wraps the
input ListAdapter {\emph and} ListView wraps the wrapped one). | |||||||||||
Use this to move the check state of an item from one position to another
in a drop operation.
| |||||||||||
Move an item, bypassing the drag-sort process.
| |||||||||||
Use this when an item has been deleted, to move the check state of all
following items up one step.
| |||||||||||
Removes an item from the list and animates the removal.
| |||||||||||
For each DragSortListView Listener interface implemented by
adapter , this method calls the appropriate
set*Listener method with adapter as the argument. | |||||||||||
Allows for easy toggling between a DragSortListView
and a regular old ListView.
| |||||||||||
Completely custom scroll speed profile.
| |||||||||||
Set the width of each drag scroll region by specifying
a fraction of the ListView height.
| |||||||||||
Set the width of each drag scroll region by specifying
a fraction of the ListView height.
| |||||||||||
This better reorder your ListAdapter! DragSortListView does not do this
for you; doesn't make sense to.
| |||||||||||
Usually called from a FloatViewManager.
| |||||||||||
Set maximum drag scroll speed in positions/second.
| |||||||||||
Probably a no-brainer, but make sure that your remove listener
calls
notifyDataSetChanged() or something like it. | |||||||||||
Start a drag of item at
position using the
registered FloatViewManager. | |||||||||||
Start a drag of item at
position without using
a FloatViewManager. | |||||||||||
Stop a drag in progress.
| |||||||||||
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() |
Drag flag bit. Floating View can move in the negative x direction.
Drag flag bit. Floating View can move in the negative y direction. This is subtle. What this actually means is that the floating View can be dragged above its starting position. Remove in favor of lower-bounding item position?
Drag flag bit. Floating View can move in the positive x direction.
Drag flag bit. Floating View can move in the positive y direction. This is subtle. What this actually means is that, if enabled, the floating View can be dragged below its starting position. Remove in favor of upper-bounding item position?
Cancel a drag. Calls #stopDrag(boolean, boolean) with
true
as the first argument.
As opposed to getAdapter()
, which returns
a heavily wrapped ListAdapter (DragSortListView wraps the
input ListAdapter {\emph and} ListView wraps the wrapped one).
Use this to move the check state of an item from one position to another
in a drop operation. If you have a choiceMode which is not none, this
method must be called when the order of items changes in an underlying
adapter which does not have stable IDs (see
hasStableIds()
). This is because without IDs, the
ListView has no way of knowing which items have moved where, and cannot
update the check state accordingly.
A word of warning about a "feature" in Android that you may run into when dealing with movable list items: for an adapter that does have stable IDs, ListView will attempt to locate each item based on its ID and move the check state from the item's old position to the new position — which is all fine and good (and removes the need for calling this function), except for the half-baked approach. Apparently to save time in the naive algorithm used, ListView will only search for an ID in the close neighborhood of the old position. If the user moves an item too far (specifically, more than 20 rows away), ListView will give up and just force the item to be unchecked. So if there is a reasonable chance that the user will move items more than 20 rows away from the original position, you may wish to use an adapter with unstable IDs and call this method manually instead.
Move an item, bypassing the drag-sort process. Simply calls
through to drop(int, int)
.
from | Position to move (NOTE: headers/footers ignored! this is a position in your input ListAdapter). |
---|---|
to | Target position (NOTE: headers/footers ignored! this is a position in your input ListAdapter). |
Use this when an item has been deleted, to move the check state of all
following items up one step. If you have a choiceMode which is not none,
this method must be called when the order of items changes in an
underlying adapter which does not have stable IDs (see
hasStableIds()
). This is because without IDs, the
ListView has no way of knowing which items have moved where, and cannot
update the check state accordingly.
See also further comments on moveCheckState(int, int)
.
Removes an item from the list and animates the removal.
which | Position to remove (NOTE: headers/footers ignored! this is a position in your input ListAdapter). |
---|
For each DragSortListView Listener interface implemented by
adapter
, this method calls the appropriate
set*Listener method with adapter
as the argument.
adapter | The ListAdapter providing data to back DragSortListView. |
---|
Allows for easy toggling between a DragSortListView and a regular old ListView. If enabled, items are draggable, where the drag init mode determines how items are lifted (see setDragInitMode(int)). If disabled, items cannot be dragged.
enabled | Set true to enable list
item dragging
|
---|
Completely custom scroll speed profile. Default increases linearly
with position and is constant in time. Create your own by implementing
DragSortListView.DragScrollProfile
.
Set the width of each drag scroll region by specifying a fraction of the ListView height.
heightFraction | Fraction of ListView height. Capped at 0.5f. |
---|
Set the width of each drag scroll region by specifying a fraction of the ListView height.
upperFrac | Fraction of ListView height for up-scroll bound. Capped at 0.5f. |
---|---|
lowerFrac | Fraction of ListView height for down-scroll bound. Capped at 0.5f. |
This better reorder your ListAdapter! DragSortListView does not do this
for you; doesn't make sense to. Make sure
notifyDataSetChanged()
or something like it is called
in your implementation. Furthermore, if you have a choiceMode other than
none and the ListAdapter does not return true for
hasStableIds()
, you will need to call
moveCheckState(int, int)
to move the check boxes along with the
list items.
Usually called from a FloatViewManager. The float alpha will be reset to the xml-defined value every time a drag is stopped.
Set maximum drag scroll speed in positions/second. Only applies if using default ScrollSpeedProfile.
max | Maximum scroll speed. |
---|
Probably a no-brainer, but make sure that your remove listener
calls notifyDataSetChanged()
or something like it.
When an item removal occurs, DragSortListView
relies on a redraw of all the items to recover invisible views
and such. Strictly speaking, if you remove something, your dataset
has changed...
Start a drag of item at position
using the
registered FloatViewManager. Calls through
to startDrag(int, View, int, int, int)
after obtaining
the floating View from the FloatViewManager.
position | Item to drag. |
---|---|
dragFlags | Flags that restrict some movements of the
floating View. For example, set dragFlags |=
~ to allow dragging the floating
View in all directions except off the screen to the left. |
deltaX | Offset in x of the touch coordinate from the left edge of the floating View (i.e. touch-x minus float View left). |
deltaY | Offset in y of the touch coordinate from the top edge of the floating View (i.e. touch-y minus float View top). |
startDrag
will fail if we are not currently in
a touch event, there is no registered FloatViewManager,
or the FloatViewManager returns a null View.
Start a drag of item at position
without using
a FloatViewManager.
position | Item to drag. |
---|---|
floatView | Floating View. |
dragFlags | Flags that restrict some movements of the
floating View. For example, set dragFlags |=
~ to allow dragging the floating
View in all directions except off the screen to the left. |
deltaX | Offset in x of the touch coordinate from the left edge of the floating View (i.e. touch-x minus float View left). |
deltaY | Offset in y of the touch coordinate from the top edge of the floating View (i.e. touch-y minus float View top). |
startDrag
will fail if we are not currently in
a touch event, floatView
is null, or there is
a drag in progress.
Stop a drag in progress. Pass true
if you would
like to remove the dragged item from the list.
remove | Remove the dragged item from the list. Calls a registered RemoveListener, if one exists. Otherwise, calls the DropListener, if one exists. |
---|