开发者

Issue to call setMessage() on ProgressDialog

I'm having an issue creating a ProgressDialog in my onCreateDialog() method. The code is as follows:

Dialog dialog;
switch(id){
    case CONNECTING:
        dialog = new ProgressDialog(this);
        dialog.setMessage("Connecting").setTitle("");
        return dialog;

Eclipse throws me an error setMessage wouldn't be a valid Method of the type ProgressDialog, though I expect it to be there since the documentation for API8 (which I use) says so. AFAIK the instantiation should be possible s开发者_JAVA百科ince ProgressDialog ihnerits from Dialog right?

Can someone help me at this? It's really weird.


You need to change your code to:

Dialog dialog;
switch(id){
    case CONNECTING:
        dialog = new ProgressDialog(this);
        ((ProgressDialog)dialog).setMessage("Connecting");
        dialog.setTitle("");
        return dialog;

Alliteratively, you can change dialog to type ProgresssDialog if you are always returning a ProgresssDialog, but I doubt it.


The issue is that Dialog doesn't have a setMessage method. Which is the type of the variable dialog.

Edit: This line:

dialog.setMessage("Connecting").setTitle("");

Also looks wrong since setMessage() returns void.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜