以下代码工作正常,但进度对话框未显示,我想在进程DownloadData()运行时显示它。
此活动不是唯一的,也不是主要活动。
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();
}
}
答案 0 :(得分:3)
您似乎在创建对话框后几乎立即将其关闭。如果你删除会怎么样?
dialog.dismiss();
下载内容时,您应该考虑使用AsyncTask。在下载时显示进度对话框非常棒。 http://developer.android.com/reference/android/os/AsyncTask.html