android - onDrag called for each RecyclerView.ViewHolder -


my ondrag method seems called each recyclerview.viewholder exists in recyclerview. know how prevent , make sure called once?

viewholder

public class viewholder extends recyclerview.viewholder implements onlongclicklistener, ondraglistener {     public imageview imgproduct;     public textview lblname;      public viewholder(view view) {         super(view);         imgproduct = (imageview)view.findviewbyid(r.id.imgshelfproduct);         imgproduct.setonlongclicklistener(this);         imgproduct.setondraglistener(this);         lblname = (textview) view.findviewbyid(r.id.lblshelftext);     }      @override     public boolean onlongclick(view view) {         clipdata data = clipdata.newplaintext("product", view.tostring());         dragshadowbuilder shadowbuilder = new view.dragshadowbuilder(view);         view.startdrag(data, shadowbuilder, view, 0);         return false;     }      @override     public boolean ondrag(view view, dragevent event) {         switch (event.getaction()) {         case dragevent.action_drag_started:             log.d(shoppingapplication.tag, "started");             return true;         case dragevent.action_drag_entered:             log.d(shoppingapplication.tag, "entered");             return true;         case dragevent.action_drag_exited:             log.d(shoppingapplication.tag, "exited");             return true;         case dragevent.action_drag_ended:             log.d(shoppingapplication.tag, "ended");             return true;         default:             break;         }         return false;     } } 

oncreateviewholder

@override public viewholder oncreateviewholder(viewgroup parent, int viewtype) {     view view = layoutinflater.from(parent.getcontext()).inflate(r.layout.item_shelf_product, parent, false);     return new viewholder(view); } 

onbindviewholder

@override public void onbindviewholder(viewholder viewholder, int position) {     product product = products.get(position);     viewholder.lblname.settext(product.getname());     string url = app.getimagepath();     picasso.with(activity).load(url).into(viewholder.imgproduct); } 

i must have misunderstood concept of ondraglistener. not supposed added draggable views, view want them dragged onto. moved out of recyclerview.adapter class , activity class , added target view.

now ondrag method called once per trigger.


Comments