I am implementing a DialogPreference
in a class. I want that when the positive button of the dialog is clicked, the dialog should not dismiss. I am using the logic from this answer.
Insided the class I use:
protected void onPrepareDialogBuilder(Builder builder) {
super.onPrepareDialogBuilder(builder);
final AlertDialog d = builder.create();
d.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
Toast.makeText(mContext, "inside", Toast.LENGTH_SHORT).show();
Button b = d.getButton(DialogInterface.BUTTON_POSITIVE);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// TODO Do something
// Dismiss once everything is OK.
d.dismiss();
}
});
}
});
}
But when I open the dialog, I do not see the Toast
,and the dialog closes. So how is my implementation of that answer wrong?