2
我有一個公共類,它具有一些常見的泛型函數,例如用於在我的應用程序中顯示對話框。我製作了一個通用的函數,並且希望在使用對話框時在活動中調用它。我對Java很新,所以請原諒,如果它非常基本。如何調用泛型活動finish
public static class AlertDialogs{
public static void alertButtonDialog(Activity activity, Context context, String title, String message,
String positiveButton, String negativeButton) {
AlertDialog.Builder alertBuilder = new AlertDialog.Builder(context);
alertBuilder.setTitle(title);
alertBuilder.setMessage(message);
alertBuilder.setPositiveButton(positiveButton, new OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Activity.this.finish(); // *?? How to do this part ??*
// the activity to be finished is the activity which calls this function
}
})
}
}
在任何其他活動後來,每當我顯示對話框,我只想做
AlertDialogs.alertButtonDialog(...all my Strings...)
這僅僅是爲了方便訪問。
真棒謝謝! – devgp
...或者您使用**應用程序上下文**,但它不是很常見 – rupps