Bir EditTextnesneyle bir uyarı iletişim kutusu oluşturmaya çalışıyorum . Başlangıç metnini EditTextprogramlı olarak ayarlamam gerekiyor . İşte sahip olduğum şey.
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();
Geçerli bir EditTextnesneye sahip olabilmem için neyi değiştirmem gerekiyor ?
[Düzenle]
Yani, user370305 ve kullanmam gereken diğerleri tarafından belirtildi alertDialog.findViewById(R.id.label_field);
Maalesef burada başka bir sorun var. Görünüşe göre, içerik görünümünü ayarlamak AlertDialogprogramın çalışma zamanında çökmesine neden oluyor. Yapıcıda ayarlamalısın.
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();
Ne yazık ki, bunu yaptığınızda alertDialog.findViewById(R.id.label_field);şimdi geri dönüyor null.
[/Düzenle]
dialogBuilder.setView(R.layout.dialog_layout);