I have a DialogFragment
working correctly. However, I need to disable the "OK" button if two text fields are empty. In the case where they are not empty, the "OK" button should be clickable and proceed. How to go about this?
If have the following code:
return new AlertDialog.Builder(getActivity())
.setView(view)
.setPositiveButton(android.R.string.ok,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (!isDual) {
if (sms.getText().toString().isEmpty() || minutes.getText().toString().isEmpty() || dialog.toString().isEmpty()) {
Toast.makeText(getActivity(), "All Fields Required", Toast.LENGTH_SHORT).show();
getDialog().create();
} else {
saveToDb();
}
} else {
// Dual Phone
if (sms.getText().toString().isEmpty() || minutes.getText().toString().isEmpty() || dialog.toString().isEmpty()) {
if (sms2.getText().toString().isEmpty() || minutes2.getText().toString().isEmpty() || d.toString().isEmpty()) {
Toast.makeText(getActivity(), "All Fields Required", Toast.LENGTH_SHORT).show();
getDialog().show();
}
Toast.makeText(getActivity(), "All Fields Required", Toast.LENGTH_SHORT).show();
getDialog().show();
} else {
saveToDb2();
}
}
}
}
)
.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
})
.create();