0

AlertDialog.builder で構築した alertDialog があります。

次に、作成したカスタム xml レイアウトを指定します。

そのレイアウトには、onclick メソッドを使用したイメージビューがあります。

それらをクリックすると、うまく機能するコードを実行したいのですが、ダイアログウィンドウも閉じたいです。

それ、どうやったら出来るの?ダイアログへの参照がないようで、ダイアログに ID を与えることができませんか?

現在、ダイアログをパブリックフィールドに保存してから、その参照を指すことでダイアログを閉じていますが、それは恐ろしい方法のようです。

助けてくれてありがとう:)

編集: 私のコード ` AlertDialog.Builder alert = new AlertDialog.Builder(this);

    alert.setTitle("Choose Color");
    LayoutInflater inflater = this.getLayoutInflater();
    View v = inflater.inflate(R.layout.colorpicker, null);
    alert.setView(v);
    Dialog d=alert.create();`

colorpicker レイアウトには 16 の異なるイメージビューがあり、クリックすると changecolor メソッドを実行します (現在の色を変更します)。

4

2 に答える 2

0

To best answer your question we need you to post a code sample but you can try this

.setNegativeButton(android.R.string.cancel,new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog,int id) {
                    // if this button is clicked, just close
                    // the dialog box and do nothing
                    dialog.cancel();
                }
            });
于 2013-07-25T00:37:40.533 に答える