Alertdialog - Removeview Has To Get Called
I have a alert dialog with a editText area. When I call it a second time, the app crashes with error: 02-28 23:25:08.958: E/AndroidRuntime(11533): java.lang.IllegalStateException:
Solution 1:
AlertDialog.Builder.show
create a new instance of Alert
from the content of the Builder
, including the view given in setView
.
Therefore, your input
will be added to both the alerts
. To prevent this, use create
to create a final instance of your AlertDialog
and call show
on this one:
finalAlertDialogalertDialog= alert.create();
[...]
// in onClick
alertDialog.show();
On a broader perspective, you should use showDialog(int id)
and the associated methods onCreateDialog
and onPrepareDialog
. However, all this is now deprecated if you use Fragments
, in which case you should use a DialogFragment
Post a Comment for "Alertdialog - Removeview Has To Get Called"