android - why alertbox is closing after clicking ok button? -


this question has answer here:

 @override  protected dialog oncreatedialog(int id)     {      final alertdialog.builder alert = new alertdialog.builder(this);         alert.settitle("test");     alert.seticon(r.drawable.logo1);     alert.setmessage("lorem ipsum dolor sit amet, consectetuer adipiscing elit. nam cursus.");     linearlayout lila1= new linearlayout(this);     lila1.setorientation(1); //1 vertical orientation     final edittext input = new edittext(this);      final edittext input1 = new edittext(this);     input.setid(0);     input1.setid(1);     input.sethint("enter email");     input1.sethint("enter message");     input1.setheight(200);     lila1.addview(input);     lila1.addview(input1);     alert.setview(lila1);      alert.setpositivebutton("send", new dialoginterface.onclicklistener()      {           public void onclick(dialoginterface dialog, int whichbutton)         {                               string value = input.gettext().tostring().trim();                   string value1 = input1.gettext().tostring().trim();                    int emailin= input.gettext().tostring().length();                 int message=input1.gettext().tostring().length();                if( emailin == 0 || message==0 )               {                    if(emailin==0)                 {                 input.seterror("name required");                 //dialogbox should not close.                 }                 if(message==0)                   {                 input1.seterror("description required");                            //dialogbox should not close.                 }                }               else             {          // toast.maketext(getapplicationcontext(), value, toast.length_short).show();                   // toast.maketext(getapplicationcontext(), value1, toast.length_short).show();               intent email = new intent(intent.action_send);             email.putextra(intent.extra_email, new string[]{getresources().getstring(r.string.toemail)});                      email.putextra(intent.extra_subject, "test");             email.putextra(intent.extra_text, value +  value1);             email.settype("message/rfc822");             startactivity(intent.createchooser(email, "choose email:"));              }             }});           alert.setnegativebutton("cancel",                         new dialoginterface.onclicklistener()         {                                        public void onclick(dialoginterface dialog, int whichbutton) {                           dialog.cancel();            }});              return alert.create();        }     } 

i checking condition in setpositivebutton. after checks condition alert box closed automatically. want alertbox show until process completed. have implemented lot of things, unable find solution.

i tried once not able find solution , here did. donot use setpositivebutton, or negative or neutral button because of these bydefault close dialog box. since hav created linearlayout lila1= new linearlayout(this); add 2 buttons dynamically , add click listner on them , when done logic call onbackpressed()

here code:

linearlayout lila1= new linearlayout(this);     linearlayout linbuttons = new linearlayout(this);     linbuttons.setorientation(linearlayout.horizontal);     button btnpositive = new button(this);     button btnnegative = new button(this);     btnpositive.settext("send");     btnpositive.setonclicklistener(new onclicklistener() {          @override         public void onclick(view v) {             // write code sending             onbackpressed();         }     });     btnnegative.settext("cancel");     btnnegative.setonclicklistener(new onclicklistener() {          @override         public void onclick(view v) {             onbackpressed();         }     });     linbuttons.addview(btnpositive);     linbuttons.addview(btnnegative);     lila1.addview(linbuttons); 

Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -