imagebutton - Android GUI :: Continuous click events hangs -
hello have 1 imagebutton single image. have added onclick event , works fine.when imagebutton clicked add entry function works.
now when user continously clicks imagebutton, add entry functions executes many times same data. want prevent it. such that, imagebutton should not queue process next click event until function gets executed completely.
i tried myimagebutton.setenable(false)
onclick event executes. , doing
myimagebutton.setenable(true)
after data entry function.
i tried put code in myimagebutton.isenabled()
didnt work.
how ignore such queued click events? there other way (than setenable()
) ignore/eat click processing?
i have checked putting println statements each click event in sync...means code executes in order.
edit
private onclicklistener m_addclickhandler = new onclicklistener() { public void onclick(view v) { if(m_bdoadd) { m_bdoadd = false; new addtask().execute(); } else logdata("add::onclick::not clicked"); } }; private class addtask extends asynctask<void, void, integer> { @override protected integer doinbackground(void... params) { logdata("doinbg, start"+m_bdoadd); int istatus =add(m_data); logdata("doinbg, start end, status="+istatus+"flag="+m_bdoadd); return istatus; } @override protected void onpostexecute(integer result) { logdata("onpostexec, start"+m_bdoadd); int istatus = result; if (istatus == 0) { toast.maketext(getapplicationcontext(), r.string.stradded, toast.length_short).show(); } else if (istatus == 1) { toast.maketext(getapplicationcontext(), r.string.stralreadyexists, toast.length_short).show(); } else { toast.maketext(getapplicationcontext(), r.string.straddfailed, toast.length_short).show(); } m_bdoadd = true; logdata("onpostexec, end"+m_bdoadd); } } void add() { // add info db (takes few msecs) }
i still not getting "add::onclick::not clicked" in log.
any further clue?
try inside onclick handler:
myimagebutton.setclickable(false);
update:
this how events work in android:
- when user clicks view event added event queue.
- events processed on edt in serial fashion: 1 after another.
- event enqueuing , event dispatching done in separate threads: processing event not prevent enqueuing new event.
a solution problem:
- you should process events fast possible , not block edt. means should long-running tasks (= database operations) in background thread - use asynctask that.
- when start background task should set flag (
backgroundworkrunning
) , clear when done. - when new event dispatched, first check
backgroundworkrunning
flag. nothing if flag set.
Comments
Post a Comment