当线程中的一个进程正在运行时,进度对话框不显示
ProgressDialog is not showing when one process in Thread is runnning
以下代码工作正常,但未显示进度对话框,我想在进程 DownloadData() 为 运行 时显示它。
这个activity不是唯一的也不是主要的
public class MyActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.MyActivity);
}
public void Download(View view) {
final ProgressDialog dialog = new ProgressDialog(MyActivity.this);
dialog.setTitle("Processing...");
dialog.setMessage("Please wait.");
dialog.setCancelable(false);
dialog.setIndeterminate(true);
dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
dialog.show();
Thread background = new Thread(new Runnable() {
public void run () {
runOnUiThread(new Runnable() {
@Override
public void run() {
DownloadData();
dialog.dismiss();
}
});
}
});
background.start();
}
}
您似乎在创建对话框后几乎立即关闭了它。如果删除会怎样?
dialog.dismiss();
您应该考虑在下载内容时使用 AsyncTask。下载时显示进度对话框非常棒。
http://developer.android.com/reference/android/os/AsyncTask.html
以下代码工作正常,但未显示进度对话框,我想在进程 DownloadData() 为 运行 时显示它。
这个activity不是唯一的也不是主要的
public class MyActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.MyActivity);
}
public void Download(View view) {
final ProgressDialog dialog = new ProgressDialog(MyActivity.this);
dialog.setTitle("Processing...");
dialog.setMessage("Please wait.");
dialog.setCancelable(false);
dialog.setIndeterminate(true);
dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
dialog.show();
Thread background = new Thread(new Runnable() {
public void run () {
runOnUiThread(new Runnable() {
@Override
public void run() {
DownloadData();
dialog.dismiss();
}
});
}
});
background.start();
}
}
您似乎在创建对话框后几乎立即关闭了它。如果删除会怎样?
dialog.dismiss();
您应该考虑在下载内容时使用 AsyncTask。下载时显示进度对话框非常棒。 http://developer.android.com/reference/android/os/AsyncTask.html