Item Address:Https://github.com/bauerca/drag-sort-listview
Introduction:Dragsortlistview is a list of supported drag-and-drop sorting by dragging and dropping data, the disadvantage is when the data
too much bad pull down.
API Introduction:
dragsortlistview.droplistener>> the listener that the position changes when the interface listens up and down;
dragsortlistview.removelistener>> This interface listens to left and right drag, sliding the interface to delete data successfully;
Floatviewmanager: Is the control of the hover box control including declaration and destruction when dragging up and down
Dragsortlistview: Set the drag switch, and set the callback listener, because the system does not know our data operation
Specific Business
Dragsortcontroller: The controller realizes the Floatviewmanager and realizes the Ontouchlistener at the same time;
indicates that most of the actions generated by the drag are inside the controller. The switch of the delete operation is also the controller;
At the same time, the definition of delete and drag is also in the controller. There is a problem here, we operate the
who the object is, the system provides the Setdraghandleid () method to set the operation's view;
/** * A simple example * @author Lean @date: 2014-10-23 */public class Mainactivity extends Activity {private Dragsortlistview M Dslv;private Dragsortcontroller Mcontroller; Arrayadapter<string> adapter; Private Dragsortlistview.droplistener OnDrop = new Dragsortlistview.droplistener () {@Override public void drop (int from, int. to) {if (from! = To) {////drag up or down, the finger releases the momentary With String item = Adapter.getitem (from); Adapter.remove (item); Adapter.insert (item, to); } } }; Private Dragsortlistview.removelistener onremove = new Dragsortlistview.removelistener () {@Ove Rride public void Remove (int which) {//delete location successfully called Adapter.remove (ADAPTER.G Etitem (which)); } }; @Overrideprotected void OnCreate (BundlE savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_main); MDSLV = ( Dragsortlistview) Findviewbyid (Android. r.id.list)///Open drag switch, if not open right slide operation does not respond mdslv.setdragenabled (true);//Set Listener Mdslv.setdroplistener (OnDrop); Mdslv.setremovelistener (onremove); Mcontroller = Buildcontroller (MDSLV);//Set the Hover box Manager, click Listener Mdslv.setfloatviewmanager (Mcontroller); Mdslv.setontouchlistener (Mcontroller); Setlistadapter ();} Public Dragsortcontroller Buildcontroller (Dragsortlistview dslv) {Dragsortcontroller controller = new Dragsortcont Roller (DSLV); Set Drag Object id mapping view Controller.setdraghandleid (R.ID.DRAG_RL); Set Remove Switch controller.setremoveenabled (true); Set drag/Remove mode Controller.setdraginitmode (Dragsortcontroller.on_drag); Controller.setremovemode (Dragsortcontroller.fling_remove); return controller; The public void Setlistadapter () {string[] array = getresources (). Getstringarray (R.array.jazz_artist_names); arraylist<string> list = new Arraylist<string> (arrays.aslist (array)); adapter = new Arrayadapter<string> (this, r.layout.list_item_handle_left, R.id.text, list); Mdslv.setadapter (adapter); } }
Android Open Source--dragsortlistview