将不会在android中显示progressDialog
我有一个加载进度对话框的第二个活动,我在我的android项目后按下按钮,但pogressdialog没有加载它。 你能帮我吗? 感谢和抱歉我的英语!将不会在android中显示progressDialog
的代码是...
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();
你应该管理(显示/删除)的进展从UI线程,而不是您的自定义线程内对话框。
该解决方案适用于我,如果我有我的当前活动中定义的progressDialog
成员:显示10秒
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();
}
});
进度对话框,然后它就会被解雇。
你有什么要确保是:
- 你是在
programacion
活动内(即在ProgressDialog.show
法规定)。 -
calcularFecha(horaIn, horaFi);
不会引发任何异常。
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");
}
试试这个
没有用!我看到,如果我把简单的敬酒也不要显示它! :-(enviar.setOnClickListener(new OnClickListener(){public void onClick(View v){calcularFecha(horaIn,horaFi); Log.d(“PRUEBA”,“COMENZAMOS LA PARTE DE LA CONEXION”); Toast.makeText(getApplicationContext (),“WOL + CONEXTION”,Toast.LENGTH_SHORT).show(); Toast.makeText(programacion.this,“WOL + CONEXTION”,Toast.LENGTH_SHORT).show(); // getApplicationContext()Log.d “PRUEBA”,“MOSTRAMOS PROGRESS”); – mmm286 2011-04-28 14:15:20
试试这个,如果你的作品..
ProgressDialog更新=新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();
}
没有什么作用!我已经看到,如果我把简单的吐司也不显示它!:-(enviar.setOnClickListener(new OnClickListener(){public void onClick(View v ){calcularFecha(horaIn,horaFi); Log.d(“PRUEBA”,“COMENZAMOS LA PARTE DE LA CONEXION”); Toast.makeText(getApplicationContext(),“WOL + CONEXTION”,Toast.LENGTH_SHORT).show(); Toast.makeText(programacion.this,“WOL + CONEXTION”,Toast.LENGTH_SHORT).show(); // getApplicationContext()Log.d(“PRUEBA”,“MOSTRAMOS PROGRESS”); – mmm286 2011-04-28 14:15:07
尝试将clicklistener放在这样...按钮b1 = (按钮)findViewById(R.id.button1); \t b1.setOnClickListener(新View.OnClickListener(){ \t \t \t @Override \t \t \t公共无效的onClick(视图v){ \t \t \t \t // TODO自动生成方法存根 \t \t \t \t Toast.makeText(Classname.this,“Hello”,Toast.LENGTH_SHORT).show(); \t \t \t} \t \t \t \t \t}); – 2011-04-29 05:39:28
我觉得你ProgressDialog
连接到错误Activity
(如Context
)。
你没有张贴满级的源代码,但这个问题可能是programacion.this
:
ProgressDialog.show(programacion.this, "", "Loading...");
没有什么工作! 我已经看到,如果我把简单的吐司也不显示它! :-( enviar.setOnClickListener(新OnClickListener() \t { \t \t \t \t公共无效的onClick(视图v){ \t \t \t \t \t \t \t \t \t \t calcularFecha(horaIn,horaFi); \t \t \t \t \t \t日志。d(“PRUEBA”,“COMENZAMOS LA PARTE DE LA CONEXION”); Toast.makeText(getApplicationContext(),“WOL + CONEXTION”,Toast.LENGTH_SHORT).show(); \t \t Toast.makeText(programacion.this,“WOL + CONEXTION”,Toast.LENGTH_SHORT).show(); \t \t \t // getApplicationContext() \t \t \t Log.d( “PRUEBA”, “MOSTRAMOS PROGRESS”); ........... – mmm286 2011-04-28 13:52:27
我已经分享了一个很好的示例代码。请看看,如果你仍然有问题,请分享你的LogCat堆栈跟踪。谢谢! – rekaszeru 2011-04-28 14:33:13
Thanks.Now它的工作原理。我不知道会发生什么。我评论下我有的代码的下一行。这些线是:\t \t \t \t如果(pruebaPing( “221.221.221.2”)){ \t \t \t \t \t Log.d( “PRUEBA”, “无llega despues德comprobar EL底漆平干草阙mandar PAQUETE。”) ; \t \t \t \t \t \t \t \t \t新tareaWOL()执行(); \t \t \t \t \t \t \t \t}否则{ \t \t \t \t \t dialogin.dismiss(); \t \t \t \t \t new tareaPing()。execute(); \t \t \t}。我不明白为什么这些线路不工作??????? – mmm286 2011-04-28 15:17:37