【问题标题】:Android calling a custom ProgressDialog - how?Android 调用自定义 ProgressDialog - 如何?
【发布时间】:2011-04-05 18:05:54
【问题描述】:

How to center progress indicator in ProgressDialog easily (when no title/text passed along)

尝试创建自定义进度对话框,但无法正常工作..

我的代码:

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();
}

但我只得到崩溃:(为什么?如何调用这个自定义对话框?

错误日志:

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)

【问题讨论】:

  • 请显示错误日志。
  • 在原始帖子中,Macarse 扩展了他的自定义对话框,来自 Dialog,而不是 ProgressDialog。也许这就是问题所在?
  • @lacas 你解决了这个问题吗?如果是,请告诉我您是如何解决的。

标签: android


【解决方案1】:

也许,你应该这样调用对话框:

public static void showLoaderDialog(String sHead, String sMess) {
  dialog=new CustomProgressDialog(mycontext);
  dialog.show(mycontext, sHead, sMess, true, true);
}

但我可能是错的。

无论如何,请展示一下,代码行指的是 CustomProgressDialog.java:37

【讨论】:

    猜你喜欢
    • 2012-12-04
    • 2013-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-18
    • 2017-03-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多