showDialog不显示自定义对话框

时间:2012-06-24 12:12:04

标签: android dialog

我刚刚定义了一个对话框作为android网站建议,但它没有显示按钮点击,一些代码scracht(我没有得到任何错误):     static final int DIALOG_A = 1;     static final 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);
                    }
                }
            });

1 个答案:

答案 0 :(得分:3)

我认为onCreateDialog应该签名为link

@Override
protected Dialog onCreateDialog(int id)

// or

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

link1