0

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();
Chirag Savsani
  • 6,020
  • 4
  • 38
  • 74
Gerardo Soriano
  • 69
  • 1
  • 10
  • 1
    Possible duplicate of [Android disable positive button on some condion in addTextChangedListener (editext)](http://stackoverflow.com/questions/14413939/android-disable-positive-button-on-some-condion-in-addtextchangedlistener-edite) – Mike M. Oct 19 '16 at 02:31
  • @Gerardo Soriano - These "sms" and "minutes" are not in the Dialog view right? – vidulaJ Oct 19 '16 at 04:18

0 Answers0