AlertDialogのAndroid ドキュメントでは、AlertDialog でカスタム ビューを設定するための次の手順と例が示されています。
より複雑なビューを表示する場合は、「body」という FrameLayout を検索して、ビューを追加します。
FrameLayout fl = (FrameLayout) findViewById(R.id.body);
fl.add(myView, new LayoutParams(FILL_PARENT, WRAP_CONTENT));
まず、それadd()
がタイプミスであり、意図されていることは明らかですaddView()
。
R.id.body を使用した最初の行に混乱しています。それは AlertDialog の body 要素のようです...しかし、コードb/cにそれを入力するだけではコンパイルエラーが発生します。R.id.body はどこで定義または割り当てられますか?
これが私のコードです。ビルダーで使用しようとしsetView(findViewById(R.layout.whatever)
ましたが、うまくいきませんでした。手動で膨らませていないからだと思いますか?
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Title")
.setCancelable(false)
.setPositiveButton("Go", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
EditText textBox = (EditText) findViewById(R.id.textbox);
doStuff();
}
});
FrameLayout f1 = (FrameLayout)findViewById(R.id.body /*CURRENTLY an ERROR*/);
f1.addView(findViewById(R.layout.dialog_view));
AlertDialog alert = builder.create();
alert.show();