Android drag and drop image: ACTION_DROP never called -


i followed tutorial here: http://www.tutorialspoint.com/android/android_drag_and_drop.htm want make image draggable on screen. added framelayout xml file , added image inside of it. problem dragevent.action_drop never gets called. made sure implement ondrag on container framelayout , return true, still isn't getting called.

//mainactivity.java public class mainactivity extends activity { imageview ima; private static final string imageview_tag = "android logo"; private android.widget.framelayout.layoutparams layoutparams; string msg; int x_cord = 0; int y_cord = 0;  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);      framelayout container = (framelayout) findviewbyid(r.id.container);      container.setondraglistener(new ondraglistener() {          @override         public boolean ondrag(view arg0, dragevent arg1) {             return true;         }      });      ima = (imageview) findviewbyid(r.id.iv_logo);     ima.bringtofront();     ima.settag(imageview_tag);      ima.setonlongclicklistener(new view.onlongclicklistener() {         @override         public boolean onlongclick(view v) {             clipdata.item item = new clipdata.item((charsequence) v                     .gettag());              string[] mimetypes = { clipdescription.mimetype_text_plain };             clipdata dragdata = new clipdata(v.gettag().tostring(),                     mimetypes, item);              // instantiates drag shadow builder.             view.dragshadowbuilder myshadow = new dragshadowbuilder(ima);              // starts drag             v.startdrag(dragdata, // data dragged                     myshadow, // drag shadow builder                     null, // no need use local data                     0 // flags (not used, set 0)             );             return true;         }     });      // create , set drag event listener view     ima.setondraglistener(new ondraglistener() {         @override         public boolean ondrag(view v, dragevent event) {             layoutparams = (framelayout.layoutparams) v.getlayoutparams();              switch (event.getaction()) {             case dragevent.action_drag_started:                 log.d(msg, "action dragevent.action_drag_started");                 // nothing                 break;             case dragevent.action_drag_entered:                 log.d(msg, "action dragevent.action_drag_entered");                 x_cord = (int) event.getx();                 y_cord = (int) event.gety();                 break;             case dragevent.action_drag_exited:                 log.d(msg, "action dragevent.action_drag_exited");                 x_cord = (int) event.getx();                 y_cord = (int) event.gety();                 // layoutparams.leftmargin = x_cord;                 // layoutparams.topmargin = y_cord;                 log.e("y cord", string.valueof(y_cord));                 // v.setlayoutparams(layoutparams);                 break;             case dragevent.action_drag_location:                 log.d(msg, "action dragevent.action_drag_location");                 x_cord = (int) event.getx();                 y_cord = (int) event.gety();                 break;             case dragevent.action_drag_ended:                 log.d(msg, "action dragevent.action_drag_ended");                 // y_cord = (int) event.gety();                 // layoutparams.leftmargin = x_cord;                 log.e("y cord action drag ended", string.valueof(y_cord));                  layoutparams.topmargin = y_cord;                 // log.e("y cord", string.valueof(y_cord));                 v.setlayoutparams(layoutparams);                  // nothing                 break;              case dragevent.action_drop:                 log.d(msg, "action_drop event");                  y_cord = (int) event.gety();                 log.e("y cord action drop", string.valueof(y_cord));                  // layoutparams.leftmargin = x_cord;                 layoutparams.topmargin = y_cord;                 v.setlayoutparams(layoutparams);                  // nothing                 break;             default:                 break;             }             return true;         }     });  } 

}

//activity_main.xml <?xml version="1.0" encoding="utf-8"?>  <framelayout xmlns:android="http://schemas.android.com/apk/res/android"     android:id="@+id/container"     android:layout_width="match_parent"     android:layout_height="wrap_content"     android:layout_weight="0.70"     android:orientation="vertical" >      <imageview         android:id="@+id/iv_logo"         android:layout_width="167dp"         android:layout_height="117dp"         android:src="@drawable/butterfly" />  </framelayout> 

the action_drop gets called on container's drag listener not image that's being dragged.


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -