我目前有这个:
Builder yesandno = new AlertDialog.Builder(this);
yesandno.setTitle("QuickResponse");
yesandno.setMessage(message);
yesandno.setPositiveButton("YES", null);
yesandno.setNegativeButton("NO", null);
yesandno.show();
Run Code Online (Sandbox Code Playgroud)
如何通过设置一个事件监听器来捕获用户单击是或否?
当你打电话setPositiveButton()而setNegativeButton()不是传球时null你应该传球DialogInterface.OnClickListener.
例如:
yesandno.setPositiveButton("YES", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//User clicked yes!
}
});
Run Code Online (Sandbox Code Playgroud)