I made a dialog with EditText. There are "Yes" and "No" buttons. For example, if you click the "Yes" button, the input is checked and the dialog is turned off. But even if the input is wrong, the dialog is turned off. Even if the button is pressed, if the input value is wrong, it cannot be turned off?
android dialog android-alertdialog android-dialog android-dialogfragment
This should only work with API 8 and above.
In AlertDialog's onShowListener, you can override the onClickListener buttonYo
final AlertDialog d = new AlertDialog.Builder(context)
.setView(v)
.setTitle(R.string.my_title)
.setPositiveButton(android.R.string.ok, null) //onClick. Please make it null.
.setNegativeButton(android.R.string.cancel, null)
.create();
d.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
Button b = d.getButton(AlertDialog.BUTTON_POSITIVE);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// giving a condition
// If the input value is good, dialog is off
d.dismiss();
}
});
}
});
© 2024 OneMinuteCode. All rights reserved.