I’m trying to call my alertdialog from another class in same file. Where do i have wrong here? Just trying to extends the AlertDialog, but i’m not sure how to do this, i don’t want to be in my public main class, trying that and work but i need to be in separable class if this is possible.
class MyDialog extends AlertDialog {
public static Context context;
public static int theme;
protected MyDialog(Context context, int theme) {
super(context, theme);
MyDialog.context = context;
theme = THEME_HOLO_DARK;
MyDialog.theme = theme;
}
public void onCreateAlertDialog() {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(context);
alertDialog.setTitle("Auto Start")
.setMessage("Start playing after: 30 sec")
.setIcon(R.drawable.info)
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Toast.makeText(context, "Auto start cancaled!", Toast.LENGTH_SHORT).show();
dialog.cancel();
}
}
);
alertDialog.show();
}
}
I call it from main class like this:
Context context = MyDialog.context;
int i = MyDialog.theme;
MyDialog md = new MyDialog(context, i);
md.onCreateAlertDialog();
I think that it comes from the context variable that you didn’t initialize it.
You should get it from the activity your are calling the dialog from :