I am trying to add a yes/no confirmation popup to an android OnClickListener. Is it OK to use an AlertDialog.Builder in a setOnClickListener or should I be taking a different approach? I have stepped through the following code using the eclipse/android debug environment and expect the popup to appear at the .create, awaiting user response, but it does not. I am new to android and java so I may be missing something obvious. Any advice, ideas, or direction would be appreciated.
public class Controller extends Activity {
...
buttonOn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
new AlertDialog.Builder(Controller.this)
.setIcon(R.drawable.ic_menu_help)
.setMessage("Are You Sure?")
.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
// Positive response code
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Negative response code
}
})
.create();
}
});