【问题标题】:showDialog doesn't show custom dialogshowDialog 不显示自定义对话框
【发布时间】:2012-06-24 12:12:04
【问题描述】:

我刚刚按照 android 网站的建议定义了一个对话框,但它没有在按钮单击时显示,一些代码 scracht(我没有错误): 静态最终 int DIALOG_A = 1; 静态最终 int DIALOG_B = 2; TextView textX;

protected Dialog onCreateDialog(int id, String text) {
    Dialog dialog = new Dialog(this);
    dialog.setContentView(decrytedText);
    Log.v("DialogTest", "  onCreateDialog(): +++ START +++");

    switch(id) 
    {
        case DIALOG_A:
            dialog.setTitle(this.getString(R.string.dialog_title_wrong_key));
            break;
        case DIALOG_B:
            dialog.setTitle(this.getString(R.string.dialog_title_ok_key));
            break;
    }
    return dialog;
}

 somebutton.setOnClickListener(new View.OnClickListener() 
            {
                public void onClick(View v) 
                {
                    Object butts[] = (Object []) v.getTag();

                    try 
                    {
                        Log.v("DialogTest", " try");
                        String decrypted ="OK GO";
                        textX.setText(decrypted);
                        showDialog(DIALOG_A);
                    } 
                    catch (Exception e) 
                    {
                        Log.v("DialogTest", "catch");
                        textX.setText(R.string.dialog_no_wrong_key);
                        showDialog(DIALOG_B);
                    }
                }
            });

【问题讨论】:

  • 使用 showDialog() 方法代码编辑您的帖子
  • DIALOG_DECRYPT_TEXT 常量表示什么?
  • 我只是从另一个代码中复制过来的,我打算以此作为一般示例

标签: android dialog


【解决方案1】:

我认为应该有这样的 onCreateDialog 签名 link

@Override
protected Dialog onCreateDialog(int id)

// or

@Override
protected Dialog onCreateDialog(int id, Bundle args)

link1

【讨论】:

  • 谢谢你,@Override 忘记了(但我不知道我必须说)实际上是问题
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多