android - Yes/No dialog and the lifecycle -


i'm sure fundamental question, research yields nothing useful. new application needs use yes/no dialog under few circumstances, , i'm not getting how dialogs fit application lifecycle. example, create method support type of construct:

if (yesnoalert("title", "do want try again?") == true) {    action1(); } else {    action2(); } 

the method this:

private boolean yesnoalert(string title, string message) {     final boolean returnvalue;      dialoginterface.onclicklistener dialogclicklistener = new                        dialoginterface.onclicklistener() {         @override         public void onclick(dialoginterface dialog, int which) {             switch (which){             case dialoginterface.button_positive:                 returnvalue = true;                 break;              case dialoginterface.button_negative:                 returnvalue=false;                 break;             }         }     };      alertbox = new alertdialog.builder(this);     alertbox.setmessage(message)             .settitle(title)             .setpositivebutton("yes", dialogclicklistener)             .setnegativebutton("no", dialogclicklistener)             .show(); } 

... can see, not finished - there number of things not quiet correct it. piece i'm missing how know dialog has finished... method exists can utilized application can pick on fact button has been pressed? of course, button_positive , button_negative actions respond that, question how return indicator, code that's waiting response pick again @ action1() or action2(), depending upon response.

at present, not see way application determine this, - nor valid way make method/function code. i'm missing vital piece lifecycle.

where might read on this? of course, there volumes of information available on internet this, me relative newbie it's trying drink fire hose.

this make action needs taken dynamic:

private thread actiontodo;  private void yesnoalert(string title, string message) {     dialoginterface.onclicklistener dialogclicklistener = new dialoginterface.onclicklistener()     {             @override             public void onclick(dialoginterface dialog, int which)             {                 switch (which)                 {                     case dialoginterface.button_positive:                     actiontodo.start();                     break;                      case dialoginterface.button_negative:                     break;                 }             }     };     alertdialog.builder builder = new alertdialog.builder(this);     builder.setmessage(message).setpositivebutton("yes", dialogclicklistener).setnegativebutton("no", dialogclicklistener).settitle(title).show(); } 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -