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);