I have created an app which includes popups of different dialogs.
Here is my code:
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 my question is that for each dialog I need different onClick
functions but in my case when I write another onClick
function then there will be conflict. I know by writing the onClick
function inside each dialog may solve the problem but in that case, I have to declare my variables as final so how can I do it by writing onClick
function outside for every dialog I used.