android - implement sign up actitvty with Progressdiaog and AlertDialog -
i want implement sign activity user insert his/her information click button send information web service stored information in database.
i put code connecting web service in separated thread (not in ui thread), , want display progressdialog
until connection web service finish, want display alertdialog
display different messages like(this email used try different 1 , or sign successes!)
here excuse when user click sign button :
public void signupnewuser (view v) { working = progressdialog.show(this, "working..", "connecting server"); runnable work = new runnable() { @override public void run() { edit_text_fname = (edittext) findviewbyid(r.id.edit_text_fname_signup); edit_text_lname = (edittext) findviewbyid(r.id.edit_text_lname_signup); edit_text_password = (edittext) findviewbyid(r.id.edit_text_password_signup); edit_text_email = (edittext) findviewbyid(r.id.edit_text_email_signup); s1 = (spinner) findviewbyid(r.id.spinner_signup); signupperson superson = new signupperson(); superson.f_name = edit_text_fname.gettext().tostring().trim(); superson.l_name = edit_text_lname.gettext().tostring().trim(); superson.e_mail = edit_text_email.gettext().tostring().trim(); superson.passw = edit_text_password.gettext().tostring().trim(); superson.gen = choosen_gender; superson.cou_id = s1.getselecteditemposition(); method = "signup"; soapobject request = new soapobject(namespace, method); propertyinfo p = new propertyinfo(); p.setname("superson"); p.setvalue(superson); p.settype(superson.getclass()); request.addproperty(p); soapserializationenvelope envolope = new soapserializationenvelope(soapserializationenvelope.ver11); envolope.dotnet = true; envolope.setoutputsoapobject(request); envolope.addmapping(namespace, "signupperson", new signupperson().getclass()); httptransportse ahttp = new httptransportse(url); soapprimitive res = null; try { ahttp.call(namespace+method, envolope); res = (soapprimitive) envolope.getresponse(); } catch (exception ex) { //ex.printstacktrace(); result = -1; } if (result != -1) { result = integer.parseint(res.tostring()); } working.dismiss(); } }; thread ss = new thread(work); ss.start(); switch (result) { case -1: showdialog(-1); break; case 0: showdialog(0); break; case 1: showdialog(1); break; case 2: showdialog(2); break; default:break; } } @override protected dialog oncreatedialog(int id) { switch (id) { case -1: return new alertdialog.builder(this) .settitle("error!") .setmessage("error connecting server. please try again") .seticon(r.drawable.ic_error) .setpositivebutton("ok", new dialoginterface.onclicklistener() { @override public void onclick(dialoginterface arg0, int arg1) { // todo auto-generated method stub } }) .create(); case 0: return new alertdialog.builder(this) .settitle("error!") .setmessage("you have entered exists email, please try one") .seticon(r.drawable.ic_error) .setpositivebutton("ok", new dialoginterface.onclicklistener() { @override public void onclick(dialoginterface arg0, int arg1) { // todo auto-generated method stub } }).create(); case 1: return new alertdialog.builder(this) .settitle("error!") .setmessage("server error, please try again later") .seticon(r.drawable.ic_error) .setpositivebutton("ok", new dialoginterface.onclicklistener() { @override public void onclick(dialoginterface arg0, int arg1) { // todo auto-generated method stub } }) .create(); case 2: return new alertdialog.builder(this) .settitle("registration successfully!") .setmessage("click ok sign in , start usign hello!!") .seticon(r.drawable.ic_success) .setpositivebutton("ok", new dialoginterface.onclicklistener() { @override public void onclick(dialoginterface arg0, int arg1) { // todo auto-generated method stub intent = new intent(signupactivity.this ,mainactivity.class); i.addflags(intent.flag_activity_clear_top | intent.flag_activity_new_task); startactivity(i); } }) .create(); } return null; }
here , superson
object hold user information, , result
integer indicate alertdialog
display after connection web service end.
my question when run above code ,, no alert dialog message appear ! why ?
if use asynctask have easier time doing this. think might not getting dialog because you're trying show after starting thread.
with asynctask, can have server connection running in doinbackground() on separate thread , can have dialog called in onpostexecute().
let me know if makes sense! link pretty clear on how use it. :)
edit: wanted mention, if use asynctask, allows set progressdialog in onprogressupdate() method.
Comments
Post a Comment