Android调用自定义ProgressDialog-如何?

Android调用自定义ProgressDialog-如何?,android,Android,正在尝试创建自定义progressdialog,但不起作用 我的代码: public class CustomProgressDialog extends ProgressDialog { public CustomProgressDialog(Context context) { super(context, R.style.progress_dialog); } public static CustomProgressDialog show(Context context

正在尝试创建自定义progressdialog,但不起作用

我的代码:

public class CustomProgressDialog extends ProgressDialog {

public CustomProgressDialog(Context context) {
        super(context, R.style.progress_dialog);
}

public static CustomProgressDialog show(Context context, CharSequence title,
        CharSequence message) {
    return show(context, title, message, false);
}

public static CustomProgressDialog show(Context context, CharSequence title,
        CharSequence message, boolean indeterminate) {
    return show(context, title, message, indeterminate, false, null);
}

public static CustomProgressDialog show(Context context, CharSequence title,
        CharSequence message, boolean indeterminate, boolean cancelable) {
    return show(context, title, message, indeterminate, cancelable, null);
}

public static CustomProgressDialog show(Context context, CharSequence title,
        CharSequence message, boolean indeterminate,
        boolean cancelable, OnCancelListener cancelListener) {
    CustomProgressDialog dialog = new CustomProgressDialog(context);
    dialog.setTitle(title);
    dialog.setCancelable(cancelable);
    dialog.setOnCancelListener(cancelListener);
    dialog.addContentView(new ProgressBar(context), new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    dialog.show();

    return dialog;
}
}
我想如何称呼:

public static CustomProgressDialog dialog;

public static void showLoaderDialog(String sHead, String sMess) {
    dialog=new CustomProgressDialog(mycontext).show(mycontext, sHead, sMess, true, true);
}
public static void hideLoaderDialog() {
    dialog.dismiss();
}
但我只得到了crash:(为什么?如何调用此自定义对话框

错误日志:

04-05 20:33:12.754: ERROR/AndroidRuntime(13165): android.util.AndroidRuntimeException: requestFeature() must be called before adding content
04-05 20:33:12.754: ERROR/AndroidRuntime(13165):     at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:174)
04-05 20:33:12.754: ERROR/AndroidRuntime(13165):     at com.android.internal.app.AlertController.installContent(AlertController.java:201)
04-05 20:33:12.754: ERROR/AndroidRuntime(13165):     at android.app.AlertDialog.onCreate(AlertDialog.java:260)
04-05 20:33:12.754: ERROR/AndroidRuntime(13165):     at android.app.ProgressDialog.onCreate(ProgressDialog.java:176)
04-05 20:33:12.754: ERROR/AndroidRuntime(13165):     at android.app.Dialog.dispatchOnCreate(Dialog.java:307)
04-05 20:33:12.754: ERROR/AndroidRuntime(13165):     at android.app.Dialog.show(Dialog.java:225)
04-05 20:33:12.754: ERROR/AndroidRuntime(13165):     at com.lacas.chathuProto.CustomProgressDialog.show(CustomProgressDialog.java:37)
04-05 20:33:12.754: ERROR/AndroidRuntime(13165):     at com.lacas.chathuProto.CustomProgressDialog.show(CustomProgressDialog.java:26)
04-05 20:33:12.754: ERROR/AndroidRuntime(13165):     at com.lacas.chathuProto.chathuStart.showLoaderDialog(chathuStart.java:814)
04-05 20:33:12.754: ERROR/AndroidRuntime(13165):     at com.lacas.chathuProto.chathuPROTO$12.run(chathuPROTO.java:1159)
04-05 20:33:12.754: ERROR/AndroidRuntime(13165):     at android.os.Handler.handleCallback(Handler.java:587)
04-05 20:33:12.754: ERROR/AndroidRuntime(13165):     at android.os.Handler.dispatchMessage(Handler.java:92)
04-05 20:33:12.754: ERROR/AndroidRuntime(13165):     at android.os.Looper.loop(Looper.java:123)
04-05 20:33:12.754: ERROR/AndroidRuntime(13165):     at android.app.ActivityThread.main(ActivityThread.java:4627)
04-05 20:33:12.754: ERROR/AndroidRuntime(13165):     at java.lang.reflect.Method.invokeNative(Native Method)
04-05 20:33:12.754: ERROR/AndroidRuntime(13165):     at java.lang.reflect.Method.invoke(Method.java:521)
04-05 20:33:12.754: ERROR/AndroidRuntime(13165):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
04-05 20:33:12.754: ERROR/AndroidRuntime(13165):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
04-05 20:33:12.754: ERROR/AndroidRuntime(13165):     at dalvik.system.NativeStart.main(Native Method)

也许,您应该这样调用dialog:

public static void showLoaderDialog(String sHead, String sMess) {
  dialog=new CustomProgressDialog(mycontext);
  dialog.show(mycontext, sHead, sMess, true, true);
}
但我可能错了


无论如何,show,please,代码行指的是CustomProgressDialog。java:37

show,please,错误日志。在最初的帖子中,Macarse从
dialog
,而不是
ProgressDialog
,扩展了他的自定义对话框。也许这就是问题所在?@lacas你已经解决了这个问题。如果是,请告诉我你是如何解决的。