Reputation: 1
I have a to load a progressdialog in a second activity that I have in my android project after push a button but the pogressdialog doesnt load it. Could you help me please? Thanks and sorry for my english!
The code is...
ent enviar.setOnClickListener(new OnClickListener()
{
public void onClick(View v){
calcularFecha(horaIn,horaFi);
Runtime runtime = Runtime.getRuntime();
Log.d("PRUEBA", "COMENZAMOS LA PARTE DE LA CONEXION");
//getApplicationContext()
progressDialog = ProgressDialog.show(programacion.this, "", "Loading...");
new Thread() {
public void run() {
try{
sleep(10000);
} catch (Exception e) {
Log.d("PRUEBA", e.getMessage());
}
// dismiss the progress dialog
progressDialog.dismiss();
}
}.start();
Upvotes: 0
Views: 1282
Reputation: 18243
I think your ProgressDialog
is attached to the wrong Activity
(eg Context
).
You did not post the full class source code, but the problem could be programacion.this
:
ProgressDialog.show(programacion.this, "", "Loading...");
Upvotes: 0
Reputation: 19220
You should manage (show / remove) the progress dialog from within the UI thread instead of your custom thread.
This solution works for me, if I have the progressDialog
member defined inside my current activity:
enviar.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
Log.d("PRUEBA", "COMENZAMOS LA PARTE DE LA CONEXION");
progressDialog = ProgressDialog.show(programacion.this, "", "Loading...");
calcularFecha(horaIn, horaFi);
new Thread()
{
public void run()
{
try
{
sleep(10000);
}
catch (Exception e)
{
Log.d("PRUEBA", e.getMessage());
}
progressDialog.dismiss();
}
}.start();
}
});
The progress dialog is shown for 10 seconds, then it gets dismissed.
What you have to make sure, is:
programacion
activity (that is specified in your
ProgressDialog.show
method).calcularFecha(horaIn, horaFi);
doesn't throw any exception.Upvotes: 1
Reputation: 5985
Try this if it works for you..
ProgressDialog update = new ProgressDialog(activity.this);
update.setTitle(getResources().getString(R.string.app_name)); update.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); update.setCancelable(true); update.setMax(100); update.show();
Thread background = new Thread (new Runnable() {
public void run() {
try {
// enter the code to be run while displaying the progressbar.
//
// This example is just going to increment the progress bar:
// So keep running until the progress value reaches maximum value
while (update.getProgress()<= update.getMax()) {
// wait 500ms between each update
Thread.sleep(500);
// active the update handler
progressHandler.sendMessage(progressHandler.obtainMessage());
}
} catch (java.lang.InterruptedException e) {
// if something fails do something smart
}
}
});
// start the background thread
background.start();
if(update.getProgress()== 100)
{
update.dismiss();
}
Upvotes: 0
Reputation:
ProgressDialog progressDialog= new ProgressDialog(activity.this);
progressDialog.setIndeterminate(true);
progressDialog.setCancelable(false);
progressDialog.setMessage("Please Wait");
progressDialog.show();
if(progressDialog!=null)
{
progressDialog.dismiss();
System.out.println("dialog dismissed");
}
try this
Upvotes: 0