android - How to control AlertDialog -
i have created app include popup of popup of different dialog. code have written is:
if (ldifffromtoday >= 0 && ldifffromtoday <= declarevariable.cycle_max_length) { alertdialog.builder alrtstartmonitoring = new alertdialog.builder(this); alrtstartmonitoring.settitle(" start monitoring"); alrtstartmonitoring.setmessage("set start date of cycle as"+" "+sdformatter.format(dtseldate)); alrtstartmonitoring.setpositivebutton("yes", this); alertdialog alert = alrtstartmonitoring.create(); alert.show(); } else if (dtseldate.gettime()> dtstartdate.gettime() && dtseldate.gettime() <= currentdate.gettime() && !bcyclestopped) { long ldifffromstart =dtseldate.gettime()-dtstartdate.gettime(); ldifffromstart=ldifffromstart/(1000 * 60 * 60 * 24); if (ldifffromstart >= declarevariable.cycle_min_length) { bactionok = true; alertdialog.builder alrtstartmonitoring = new alertdialog.builder(this); alrtstartmonitoring.settitle(" confirm new cycle"); alrtstartmonitoring.setmessage("set start date of cycle as" + " " + sdformatter.format(dtseldate)); alrtstartmonitoring.setpositivebutton("yes", this); alertdialog alert = alrtstartmonitoring.create(); alert.show(); } } public void onclick(dialoginterface dialog, int id) { cyclemanager.getsingletonobject().sethistorydate(dtseldate); int istopstartcount = cyclemanager.getsingletonobject().getstopstartcount(); if(istopstartcount>0) cyclemanager.getsingletonobject().setstopstartdate(dtseldate, istopstartcount); displayday(); }
now question each dialog need different onclick
functions in case when write onclick function there conflict. know writing onclick
function inside each dialog may solve problem in case have declare variables final how can writing onclick
function outside every dialog used.
another solution make alertdialog instances members of class. in onclick method:
public void onclick(dialoginterface dialog, int id) { if (dialog == m_dialog1) { // server dialog 1 } }
Comments
Post a Comment