I have a custom dialog and I want to disable the PositiveButton
if a specific EditText is empty. I couldn't find how to do that on a dialog.
Here is my code :
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.layout_add_apero, null);
builder.setView(view)
.setTitle("Super un nouvel apéro !")
.setNegativeButton("Annuler", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
}
})
.setPositiveButton("Ajouter", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
String titre_apero = editTextApero.getText().toString();
String date_apero = editTextDate.getText().toString();
listener.applyTexts(titre_apero, date_apero);
}
});
editTextApero = view.findViewById(R.id.edit_apero);
editTextDate = view.findViewById(R.id.edit_date);
return builder.create();
}
So if the field editTextApero
or editTextDate
is empty I want to disable the PositiveButton
or do a pop-up (but it would be a pop-up on a dialog who is also a kind of pop-up) to say that the user has to fill each fields.