【问题标题】:Many method on progress dialog cannot resolved进度对话框上的许多方法无法解决
【发布时间】: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


【解决方案1】:

请再次检查您引用的链接。 他使用了private ProgressDialog pDialog;,但你使用的是Dialog

Dialog 没有这些方法。

【讨论】:

    猜你喜欢
    • 2016-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-16
    相关资源
    最近更新 更多