java - OnDragListener Fires Several Times? -
i have several layouts; each containing textview
. if user drags textview
unto textview
, i'm going execute method swapfamily()
it fires several times, depending on number of families.
familyitemlayout
custom linearlayout
string
attribute attached , add'tl getters , setter attribute.
however, issue that,
private class ondropfamily implements view.ondraglistener { @override public boolean ondrag(view view, dragevent event) { textview txtdragged = (textview) event.getlocalstate(); textview txttarget = (textview) view; string familydragged = ((familyitemlayout) txtdragged.getparent()).getfamily(); string familytarget = ((familyitemlayout) txttarget.getparent()).getfamily(); switch (event.getaction()) { // signals start of drag , drop operation. case dragevent.action_drag_started: break; // signals view drag point has entered bounding box of view. case dragevent.action_drag_entered: view.setbackgroundresource(r.mipmap.pill_sun); break; // signals user has moved drag shadow outside bounding box of view. case dragevent.action_drag_exited: view.setbackgroundresource(r.mipmap.pill_sky); break; // signals view user has released drag shadow, , drag point within bounding box of view. case dragevent.action_drop: break; // signals view drag , drop operation has concluded. case dragevent.action_drag_ended: // check if drag event successful if (dropeventhandled(event)) { fixedplan.swapfamily(familydragged, familytarget); } txtdragged.setvisibility(view.visible); txttarget.setbackgroundresource(r.mipmap.pill_sky); break; } return true; } private boolean dropeventhandled(dragevent dragevent) { return dragevent.getresult(); } }
i believe should put code in action_drop
instead of action_drag_ended
http://developer.android.com/reference/android/view/dragevent.html
all views received action_drag_started event receive action_drag_ended event if not visible when drag ends.
also remember return correct value action_drop
the view should return true ondragevent(dragevent) handler or ondraglistener.ondrag() listener if accepted drop, , false if ignored drop.
Comments
Post a Comment