Hi everyone. I'm having problem with creating AlertDialog.
I would like that AlertDialog appears when i click on one button, so i put all code for creating dialog in that button listener...the same code works outside that listener but inside listener doesn't work...it doesn't call any errors but when i start emulator written is something about this: "Aplication has terminated unexpectedly"....
This is my code for that:
btsenddata.setOnClickListener(new Button.OnClickListener() {
public void onClick (View v){
AlertDialog.Builder alt_bld = new AlertDialog.Builder(getApplicationContext() ); // I've tried with "activity1.this" instead "getApplicationContext()" but it is the same result
alt_bld.setMessage("Do you want to close this window ?")
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// Action for 'Yes' Button
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// Action for 'NO' Button
dialog.cancel();
}
});
AlertDialog alert = alt_bld.create();
// Title for AlertDialog
alert.setTitle("Title");
// Icon for AlertDialog
alert.setIcon(R.drawable.icon);
alert.show();
}});
}
.... i've heard that method getApplicationContext() is creating some problems but i've tried replace it with activity.this and it doesn't work anyway... If anyone knows the reason for this or more about alertdialogs pleade answer. Thanks.