I am trying to build a custom AlertDialog
with the default theme so that I can use the same AlertDialog
at multiple places inside the code. I have created a class by extending AlertDialog
and writing my custom business logic to decide the message in the dialog. The problem is that, I see a black overlay without the dialog been shown when I call AlertDialog.show()
. Here is my code:
public class ClosestShrutiDialog extends AlertDialog {
private String mLessonId;
private Activity mActivity;
private View mParentView;
private OnClickedListener mOnClickListerner;
public ClosestShrutiDialog(@NonNull Activity activity, final String lessonId, final View parentView) {
super(activity);
this.mLessonId = lessonId;
this.mActivity = activity;
this.mParentView = parentView;
}
public void setmOnClickListerner(OnClickedListener mOnClickListerner) {
this.mOnClickListerner = mOnClickListerner;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// My business login to decide the msg related params ....
// showing message to user to select the alternate shruti ...
final String msg = mActivity.getResources().getString(R.string.user_alternate_shruti_msg,
userShrutiLabel,
closestShruti.getLabel());
this.setMessage(msg);
this.setButton(android.support.v7.app.AlertDialog.BUTTON_POSITIVE,
mActivity.getResources().getString(R.string.yes),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
if(mOnClickListerner != null) {
mOnClickListerner.proceedWithChange(closestShruti);
}
}
});
this.setButton(android.support.v7.app.AlertDialog.BUTTON_NEGATIVE,
mActivity.getResources().getString(R.string.cancel),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
}
public interface OnClickedListener {
void proceedWithChange(final Shruti closestShruti);
}
}
I am not sure why is it unable to pickup the default template and show it. When I used AlerDialog.Builder(Context)
, without creating the custom class, I was able to see the dialog properly. Any suggestions?