i'm making app sort of widgets created on fly , can re-arranged drag , drop. i'm trying implement 2 things:
- long press initiate drag , drop
- short press(or click) open menu change settings.
but i'm having problem can't cancel code in handler's postdelayed() function. i'm using following code make happen.
_sliders_item[_sliders_counter].setontouchlistener(new view.ontouchlistener() { @override public boolean ontouch(final view v, motionevent event) { handler hndlr = new handler(); runnable _run = new runnable() { @override public void run() { clipdata data = clipdata.newplaintext("", ""); view.dragshadowbuilder shadowbuilder = new view.dragshadowbuilder(v); v.startdrag(data, shadowbuilder, v, 0); v.setvisibility(view.invisible); _t1.settext("executed"); _t1.show(); } }; if (_enable_editor) { if (event.getaction() == motionevent.action_down) { hndlr.postdelayed(_run,1000); //return true; } if (event.getaction() == motionevent.action_up){ _t1.settext("menu"); _t1.show(); hndlr.removecallbacks(_run); //return true; } } return _enable_editor; } });
but problem is, when long press object, works fine. can initiate drag , drop. when short press it, code action_up event executes code inside runnable still executes. how can cancel runnable code when short press object?
you have keep references runnables
, handler
, use handler#removecallbacks()
.
so basically:
handler h = new handler(); runnable r = new runnable() { /* */ h.postdelayed(r, 1000); // when want cancel. h.removecallbacks(r);
Comments
Post a Comment