I have a layout where I have an EditText with a predefined text.
Then I have a button that, when is pressed, displays a dialog with another EditText that gets the text of the previous EditText.
This works fine. But when I edit the first EditText, and press the button again, it displays the old text, not the new.
How can I get the updated text?
This is the code (inside onCreateDialog) where I get the text from the first EditText:
final View notesDialogLayout = getLayoutInflater().inflate(R.layout.notes_dialog, null);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setView(notesDialogLayout)
.setCancelable(false)
.setPositiveButton(R.string.save, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
})
AlertDialog alert = builder.create();
mNotesEdit = (EditText) notesDialogLayout.findViewById(R.id.task_notes_dialog);
mNotesEdit.setText(mNotes.getText());
mNotes is just an EditText.
The first time the Dialog opens, it gets the updated text. From the second time, it gets always the same text, even if I edit it.
You are using onCreateDialog. This method is called once only, you must use onPrepareDialog to set your text in the dialog, which is called each time you call showDialog().
edit