[英]won't show progressDialog in android
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.在按下按钮后,我必须在 android 项目中的第二个活动中加载进度对话框,但 pogressdialog 没有加载它。 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();
You should manage (show / remove) the progress dialog from within the UI thread instead of your custom thread.您应该从 UI 线程而不是自定义线程中管理(显示/删除)进度对话框。
This solution works for me, if I have the progressDialog
member defined inside my current activity:如果我在当前活动中定义了
progressDialog
成员,则此解决方案适用于我:
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.进度对话框显示 10 秒,然后消失。
What you have to make sure, is:您必须确保的是:
programacion
activity (that is specified in your ProgressDialog.show
method).programacion
活动中(在您的ProgressDialog.show
方法中指定)。calcularFecha(horaIn, horaFi);
calcularFecha(horaIn, horaFi);
doesn't throw any exception. I think your ProgressDialog
is attached to the wrong Activity
(eg Context
).我认为您的
ProgressDialog
附加到错误的Activity
(例如Context
)。
You did not post the full class source code, but the problem could be programacion.this
:您没有发布完整的 class 源代码,但问题可能是
programacion.this
:
ProgressDialog.show(programacion.this, "", "Loading...");
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尝试这个
Try this if it works for you..试试这个,如果它适合你..
ProgressDialog update = new ProgressDialog(activity.this); ProgressDialog update = new ProgressDialog(activity.this);
update.setTitle(getResources().getString(R.string.app_name)); update.setTitle(getResources().getString(R.string.app_name)); update.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
update.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); update.setCancelable(true);
update.setCancelable(true); update.setMax(100);
update.setMax(100); update.show();
更新.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();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.