public class DialogAddSubject extends DialogFragment implements View.OnClickListener{
Button add,cancel;
EditText professorName;
EditText subjectName;
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.dialog_add_subject, null);
add = (Button) view.findViewById(R.id.addsub);
cancel = (Button) view.findViewById(R.id.cancel);
add.setOnClickListener(this);
cancel.setOnClickListener(this);
subjectName = (EditText)view.findViewById(R.id.subjectName);
professorName = (EditText)view.findViewById(R.id.professorName);
getDialog().setTitle(R.string.add_sub);
return view;
}
@Override
public void onClick(View view) {
if (view.getId()== R.id.addsub)
{
String subjName = subjectName.getText().toString();
String profName = professorName.getText().toString();
ParseObject userData = new ParseObject("UserData");
userData.put("createdBy", ParseUser.getCurrentUser());
userData.put("professor", profName);
userData.put("subject", subjName);
userData.saveInBackground();
dismiss();
Toast.makeText(getActivity(),"subject and professor successfully added",Toast.LENGTH_SHORT).show();
}
else
{
dismiss();
}
}
}
The code shown its a dialog fragment that has 2 edit texts when the add button is pressed, the text entered on the editTexts fields is saved to the database (parse.com on this case), everything works perfectly.
What I want to do is to not allow the user to add the editTexts to the data base when the fields are empty and I also want to display a message either saying that one of the fields is empty or both of them are empty.
How can I do that?