Ver Mensaje Individual
  #2 (permalink)  
Antiguo 22/03/2015, 02:48
Avatar de Profesor_Falken
Profesor_Falken
 
Fecha de Ingreso: agosto-2014
Ubicación: Mountain View
Mensajes: 1.323
Antigüedad: 9 años, 8 meses
Puntos: 182
Respuesta: Pasar Variables o Usar variables Globales

Buenas,

Eso es porque creas el dialogo desde la función de callback que maneja el evento del botón:
Código Java:
Ver original
  1. ProgressDialog dialogo = new ProgressDialog(MainActivity.this);

Al crear el dialogo desde ese ámbito (dentro de un método anónimo) luego pierdes la referencia y no tienes ningún modo de controlarlo.

Una forma sencilla de hacerlo es pasar la referencia del dialogo ya sea por constructor o mediante un metodo set. Por ejemplo:

Código Java:
Ver original
  1. private class enviar_post extends AsyncTask<String, String, String> {
  2.     private ProgressDialog dialogo;
  3.         @Override
  4.         protected String doInBackground(String... parms) {
  5.             http_request conexion = new http_request();
  6.             conexion.url("http://xxxx/android/login.php");
  7.             conexion.parametro("username", "Prueba 1");
  8.             conexion.parametro("password", "Prueba 2");
  9.             String result = conexion.post();
  10.             return result;
  11.         }
  12.  
  13.        public enviar_post setProgressDialog(ProgressDialog dialog) {
  14.             this.dialogo = dialog;
  15.             return this;
  16.        }
  17.  
  18.         protected void onPostExecute(String parms) {
  19.             startActivity(new Intent(MainActivity.this, ResultadosActivity.class));
  20.             Toast.makeText(MainActivity.this, parms, Toast.LENGTH_SHORT).show();
  21.             this.dialogo.close();
  22.         }
  23.     }
  24.  
  25. ..............
  26.  
  27.  
  28.   new enviar_post().setProgressDialog(dialogo).execute();


Un saludo
__________________
If to err is human, then programmers are the most human of us