I am trying to run a progress dialog while an other process is running, and I can't do it.
the process that I want run is 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+"' WHERE 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 is launching when I click a button. thanks!
EDIT/////////////
well I solved the problem with this 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 and then 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 I don't use a toast in a method doInBackground (FC)