java - Android: How do I make a gird of images views and have the image change when I drag another image over it? -


i trying make grid of image views, when drag view on them(this view acts mouse pointer), changes image drag on in grid different image. when drag "mouse" view away go normal.

right have mouse cursor view moving , have grid of image views implemented grid view using custom adaptor ( pictured below)

image grid

i can drag cursor around when ever try drag inside gridview, calls image on gridview's ontouch listener(only when click on image view, not when slide on it). cannot seem onhover working on images in image view.

also, if mouse view covering 1 of grid images, ontouchlistener of image view grid not called.

what best way( types of views, etc) use go implementing this?

here relevant code have far.

this set grid view in activity

gridview gridview; gridview = (gridview) findviewbyid(r.id.gridview);        gridview.setadapter(new imageadapter(this,new string [25]));     gridview.setondraglistener(new mydraglistener());     gridview.setonitemclicklistener(new adapterview.onitemclicklistener() {         public void onitemclick(adapterview<?> parent, view v,                                 int position, long id) {           }     });     gridview.setclickable(false); 

this getview function in adapter

public view getview(int position, view convertview, viewgroup parent) {      layoutinflater inflater = (layoutinflater) context             .getsystemservice(context.layout_inflater_service);      view gridview;      if (convertview == null) {          gridview = inflater.inflate(r.layout.vibe_pad_section, null);           final imageview imageview = (imageview) gridview                 .findviewbyid(r.id.grid_item_image);               imageview.setimageresource(r.drawable.vibepadcircle);             imageview.setpadding(10,10,10,10);             imageview.setontouchlistener(new view.ontouchlistener() {             @override             public boolean ontouch(view view, motionevent e) {                 log.e("here","here");                 switch (e.getaction()) {                     case motionevent.action_move:                         log.e("here2","here2");                  }                 imageview.setimageresource(r.drawable.bar_high);                 return true;             }         });           vibepad.padtargets.add(imageview);      } else {         gridview = (view) convertview;     }      return gridview; }   class  mydraglistener implements view.ondraglistener {      @override     public boolean ondrag(view v, dragevent event) {         final int action = event.getaction();         clipdata dragdata;         view p = (view) v.getparent();         object index = p.gettag();         final int = integer.parseint(index.tostring());         boolean handled = true;           log.e(" in on drag","in on drag") ;          switch (action) {               case dragevent.action_drag_exited:                  // report drop/no-drop result user                 ((imageview) v).setimageresource(r.drawable.bar_high);                 break;              case dragevent.action_drag_entered:                 // drop                 ((imageview) v).setimageresource(r.drawable.vibepadcircle);                 break;              default :                 break;         }         return handled;      } 

you need create class extends ondraglistener: when action_drag_entered occurs, can change underlying image else. when exist (you've dragged view outside bounding box of the image on gridview) can change it's original image

class  mydraglistener implements ondraglistener {      @override     public boolean ondrag(view v, dragevent event) {         final int action = event.getaction();         clipdata dragdata;         view p = (view) v.getparent();         object index = p.gettag();         final int = integer.parseint(index.tostring());         boolean handled = true;           switch (action) {             case dragevent.action_drag_started:                  dragsku = event.getclipdescription().getlabel().tostring();                                  break;              case dragevent.action_drag_ended:                   // report drop/no-drop result user                 final boolean dropped = event.getresult();                 compareinmotion = false;                 baseadapter lva = (baseadapter) gridview.getadapter();                 lva.notifydatasetchanged();                break;              case dragevent.action_drop:                 // drop                     ((imageview) v).setimagebitmap(emptyimg);                     setupcompareitem((imageview) v, dragsku);   break;              default :                 break;                         }         return handled; 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -