Android 在ProgressDialog运行时运行Toast
ProgressDialog运行时是否可以显示Toast?如果是,有一些关于如何做的例子吗 谢谢 我的当前代码不起作用:Android 在ProgressDialog运行时运行Toast,android,progressdialog,toast,Android,Progressdialog,Toast,ProgressDialog运行时是否可以显示Toast?如果是,有一些关于如何做的例子吗 谢谢 我的当前代码不起作用: final ProgressDialog pd = ProgressDialog.show( BotonesServicio.this, "Medidas", "Comprobando datos"); new Thread(new Runnable
final ProgressDialog pd = ProgressDialog.show(
BotonesServicio.this, "Medidas",
"Comprobando datos");
new Thread(new Runnable() {
public void run() {
Toast.makeText(FacturasIFirmar.this,
"Trying to show toast", Toast.LENGTH_LONG)
.show();
pd.dismiss();
}
}).start();
ProgressDialog“冻结”线程,因此所有其他操作必须在单独的线程中执行。不过,您必须在UI线程上创建toast
试着这样做:
ProgressDialog dialog = new ProgressDialog(context);
final Toast toast = Toast.makeText(context, "text", Toast.LENGTH_LONG);
Thread thread = new Thread( new Runnable() {
public void run() {
//Calculations here
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
toast.show();
}
});
thread.start();
dialog.show();
如果要与UI线程通信,应该使用AsyncTask或常规线程将消息发送给处理程序,处理程序在UI线程上执行操作
祝你好运 你应该能够做到你所期望的。你有没有不起作用的代码?你尝试过什么?上下文很重要,当两者的上下文相同时,这是可能的。首先你应该试试。