android - Run a progress dialog while an other process is running -


i trying run progress dialog while other process running, , can't it.

the process want run this:

public void onclick_editar (view view) {     float porc;     string repre;     try{         porc = float.parsefloat(edit_porcentaje.gettext().tostring());         repre = edit_representante.gettext().tostring();         try         {             hilo hilo;             hilo = new hilo(2, "update eleccion set porcentaje="+porc+", delegados='"+repre+"' id="+idd );             hilo.start();             while(hilo.isalive()){}              hilo = new hilo(4, idd);             hilo.start();             while(hilo.isalive()){}             toast.maketext(this, "¡actualizada con éxito!", toast.length_short).show();          }         catch(sqlexception e)         {             toast.maketext(this, "error: fallo en la base de datos", toast.length_short).show();         }                        }catch(exception e)     {         toast.maketext(this, "rellena todos los campos", toast.length_short).show();     } } 

this launching when click button. thanks!

edit/////////////

well solved problem code!!

public void button(view v) {       new waiting().execute(); 

}

  class waiting extends asynctask<string, void, boolean> {        progressdialog progressdialog;       protected void onpostexecute(boolean result) {              super.onpostexecute(result);              progressdialog.dismiss();           }        protected void onpreexecute() {           super.onpreexecute();           // shows progress bar dialog , call doinbackground method           progressdialog = new progressdialog(tab_adminver_modificar_eleccion.this);           progressdialog.settitle("processing....");           progressdialog.setmessage("please wait.....");           progressdialog.setcancelable(false);           progressdialog.show();                }     @override     protected boolean doinbackground(string... params) {         try {                                 thread.sleep(5000);                              } catch (exception e) {                              }         return null;     }    } 

but don't use toast in method doinbackground (fc)

you can try process run in background , progress dialog executing when process complete progress dialog dismiss..

public class asyntask1 extends asynctask<string, void, boolean> {      public asyntask1 (mainactivity activiy) {         context = activiy;     }      @override     protected void onpostexecute(boolean result) {          super.onpostexecute(result);          progressdialog.dismiss();          }      @override     protected void onpreexecute() {          super.onpreexecute();         progressdialog = new progressdialog(splash.this);         progressdialog.settitle("processing....");         progressdialog.setmessage("please wait.....");         progressdialog.setcancelable(false);         progressdialog.show();      }      @override     protected boolean doinbackground(string... params) {      // process   } 

u can call onclick or can oncreate.. better make separate class asyntask1 , write new asyntask1(mainactivity.this).execute(); want call it..

i hope helps ...


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -