2011-01-25 22 views

Respuesta

26

El mismo enfoque que en this post se verifica a trabajar (con tiempo en lugar de float):

public void timerDelayRemoveDialog(long time, final Dialog d){ 
    new Handler().postDelayed(new Runnable() { 
     public void run() {     
      d.dismiss();   
     } 
    }, time); 
} 
+1

que funciona ... fantástico. Reemplace "tiempo de flotación" por "tiempo prolongado" – Derzu

+0

Muy útil. Gracias amigo. –

2

siempre se puede hacer una clase llamada ProgressDialogWithTimeout y anular la funcionalidad de la demostración del método para devolver un ProgressDialog y establecer un temporizador para hacer lo que desea cuando que suene la alarma . Ejemplo:

private static Timer mTimer = new Timer(); 
private static ProgressDialog dialog; 

public ProgressDialogWithTimeout(Context context) { 
    super(context); 
    // TODO Auto-generated constructor stub 
} 

public ProgressDialogWithTimeout(Context context, int theme) { 
    super(context, theme); 
    // TODO Auto-generated constructor stub 
} 

public static ProgressDialog show (Context context, CharSequence title, CharSequence message) 
{ 
    MyTask task = new MyTask(); 
      // Run task after 10 seconds 
    mTimer.schedule(task, 0, 10000); 

    dialog = ProgressDialog.show(context, title, message); 
    return dialog; 
} 

static class MyTask extends TimerTask { 

    public void run() { 
     // Do what you wish here with the dialog 
     if (dialog != null) 
     { 
      dialog.cancel(); 
     } 
    } 
} 

allí tendría que llamar a esto en su código como así:

ProgressDialog progressDialog = ProgressDialogWithTimeout.show(this, "", "Loading..."); 
Cuestiones relacionadas