EditTextオブジェクトを使用して警告ダイアログを作成しようとしています。EditTextプログラムで最初のテキストを設定する必要があります。これが私が持っているものです。
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
// ...Irrelevant code for customizing the buttons and title
AlertDialog alertDialog = dialogBuilder.create();
LayoutInflater inflater = this.getLayoutInflater();
alertDialog.setContentView(inflater.inflate(R.layout.alert_label_editor, null));
EditText editText = (EditText) findViewById(R.id.label_field);
editText.setText("test label");
alertDialog.show();
有効なEditTextオブジェクトを持つために何を変更する必要がありますか?
[編集]
それで、user370305や他の人が私が使うべきだと指摘されました alertDialog.findViewById(R.id.label_field);
残念ながら、ここには別の問題があります。どうやら、コンテンツビューをに設定するAlertDialogと、プログラムが実行時にクラッシュします。ビルダーで設定する必要があります。
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
// ...Irrelevant code for customizing the buttons and title
dialogBuilder.setView(inflater.inflate(R.layout.alert_label_editor, null));
AlertDialog alertDialog = dialogBuilder.create();
LayoutInflater inflater = this.getLayoutInflater();
EditText editText = (EditText) alertDialog.findViewById(R.id.label_field);
editText.setText("test label");
alertDialog.show();
残念ながら、これを行うと、alertDialog.findViewById(R.id.label_field);が返されますnull。
[/編集]
dialogBuilder.setView(R.layout.dialog_layout);