【发布时间】:2016-09-16 04:22:09
【问题描述】:
我创建了一个程序,用于从 URL 服务器下载带有进度条的文件。
我使用来自Android Hive的参考
但我对此稍作修改。
我在课堂上使用extends Activity。并在 AsyncTask 上使用 doInBackground。
这是我的 onCreate 代码:
String TAG_NAME;
String fileUrl;
TextView teksDownload;
Dialog pDialog;
// Progress dialog type (0 - for Horizontal progress bar)
public static final int progress_bar_type = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_download);
TAG_NAME= getIntent().getStringExtra("nama_file");
fileUrl="http://myserver.com/"+TAG_NAME;
teksDownload= (TextView) findViewById(R.id.teksDownload);
teksDownload.setText("Downloading "+fileUrl);
new DownloadFileFromURL().execute(fileUrl);
}
我使用protected Dialog onCreateDialog(int id) 和class DownloadFileFromURL extends AsyncTask<String, String, String> 方法。与 Reference 这样的代码大致相同。
结果,我有 5 个错误。
找不到符号方法setMessage(String)、setIndeterminate(boolean)、setMax(int)、setProgressStyle(int)、setProgress(int)。
关于此代码:
case progress_bar_type:
pDialog = new ProgressDialog(this);
pDialog.setMessage("Downloading file. Please wait...");
pDialog.setIndeterminate(false);
pDialog.setMax(100);
pDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
pDialog.setCancelable(true);
pDialog.show();
return pDialog;
还有这段代码:
protected void onProgressUpdate(String... progress) {
// setting progress percentage
pDialog.setProgress(Integer.parseInt(progress[0]));
}
【问题讨论】:
-
您已将
pDialog声明为常规Dialog,它没有这些方法。将声明更改为ProgressDialog pDialog;。 -
@MikeM。非常感谢,为什么要评论回复?如果您在此评论中回答,我无法将其标记或接受为正确答案。
-
我正在寻找一个副本。我很确定我以前见过这个问题,但我找不到。如果您愿意,您可以接受 Pawneshwer Gupta 的回答。真高兴你做到了。干杯!
标签: java android android-asynctask download progressdialog