我希望能够重用 alertDialog 的代码,并将其作为函数调用放在另一个 Java 文件中。但是,无法使用 "this" 来替换 "MyActivity.this"?如何将其作为参数传递?最好让代码具有通用性。
AlertDialog alertDialog = new AlertDialog.Builder(MyActivity.this).create();
alertDialog.setTitle("Alert");
alertDialog.setMessage("Alert message to be shown");
alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
alertDialog.show();