I have a little issue with AlertDialog
on my application. I'm showing an AlertDialog
so user can change the text of the button he just pressed. When I do that the first time there is no problem, but if I press the button again my application crashes with the Exception in the title. Here is the code which I'm using :
public void createDialog(){
new AlertDialog.Builder(Settings.this)
.setTitle("Stampii Server Name")
.setView(input)
.setPositiveButton("Set Name", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
String serverName = input.getText().toString();
server.setText(serverName);
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
}).show();
}
server.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
createDialog();
}
});
Any ideas how can I fix that problem? I've looked at the questions similar to this, but can't find a working solution.
Thanks in advance!
.setView(input)
The variable "input" is not created in the method and is being added to a new dialog every time. This means, every time you call your create method, you are trying to add a new parent to the same object. You will need a new "input" every time you create the dialog, or you could use the same dialog over and over again.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With