android - drag and drop with onDraglistener animate to go back to original position if not dropped on target -


i making game application need use ondraglistener drag , drop here doing on class implements ondraglistener.

  @override public boolean ondrag(view v, dragevent event) {     switch (event.getaction()) {     case dragevent.action_drag_started:         log.v("here","drag started");         //no action necessary         break;     case dragevent.action_drag_entered:         //no action necessary         log.v("here","drag enteres");         break;     case dragevent.action_drag_location:      int mcurx = (int) event.getx();     int mcury = (int) event.gety();     log.v("cur(x, y) : " ,"here ::" + mcurx + ", " + mcury );     break;     case dragevent.action_drag_exited:                 //no action necessary          log.v("here","drag exits");         break;     case dragevent.action_drop:             .................do ever when dropped...      } 

here doing on touchlistener of view draged , dropped:

public boolean ontouch(view view, motionevent motionevent) {     if (motionevent.getaction() == motionevent.action_down) {         /*          * drag details: need default behavior          * - clip data set pass data part of drag          * - shadow can tailored          */         view.settag("option"+index);         clipdata data = clipdata.newplaintext("tag", "option"+index);         shadowbuilder = new view.dragshadowbuilder(view);          //start dragging item touched         view.startdrag(data, shadowbuilder, view, 0);           offsetx = (int)view.getx();//(int)motionevent.getx();          offsety = (int)view.gety();//motionevent.gety();          log.v("here","it ::" + (int)motionevent.getx() + " , "+(int)motionevent.gety());           return false;  } 

now builds shadow builder dragged anywhere drag finger. how animate shadow builder or view going position when not dropped target. tried public boolean onintercepttouchevent(motionevent event) , moving parent view , taking x,y position , animating go original position gets action cancelled. there way x,y coordinates place view dropped other target. able animate between positions.thanks in advance

you need handle drop:

switch (event.getaction()) {     case dragevent.action_drag_entered:      //break here removed in purpose can see shadow , element still @ initial place.     case dragevent.action_drop:             view view = (view) event.getlocalstate();         if (prioritieslist.contains(v)) {              viewgroup viewgroup = (viewgroup) view.getparent();             viewgroup.removeview(view);              linearlayout containview = (linearlayout) v;             containview.addview(view);             view.setvisibility(view.visible);                     break; } 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -