Reputation:
if(!(nameTextField.getText()).equals("")) {
validationBoolean = true;
}
else {
AlertDialog("Name","Customer Name","Please enter name");
nameTextField.requestFocus();
validationBoolean = false;
}
My teacher gave us this GUI project to do, I understood everything for the most part but this. I know "!" means "not" but I still don't get what this line of code is saying. I was wondering if someone can help me understand this loop.
Upvotes: -1
Views: 82
Reputation: 327
The line if(!(nameTextField.getText()).equals(""))
says:
if the text of the nameTextField is not empty then do validationBoolean = true;
but if the text of the nameTextField is empty then create a alert dialog (which will ask for input).
Upvotes: 0
Reputation: 402
(nameTextField.getText()).equals("")
This will return true if your textview is empty. So
if(!(nameTextField.getText()).equals(""))
this whole line means it is checking if your textview is empty or not. If your textview is not empty, it will return a false and the "!" will turn it into true. So if your textview is not empty the if condition will be true and the code insde the if block will execute.
Upvotes: 0
Reputation: 2285
If the name text field's text is not empty (not equal to "") then set the validation boolean = true else, Show an alert dialog, set focus on the name text field and set validation boolean to false
Let's break the first line,
if(!(nameTextField.getText()).equals(""))
Firstly, get the text from nameTextField
by using nameTextField.getText()
Secondly, Check if it is equal to "", i.e. check if the text is empty.
Finally, invert the condition using !
so that the if
block gets executed when the text is not empty.
Upvotes: 2
Reputation: 33
It checks that the value entered in nameTextField is not empty and considers the value valid in this case. Note that any whitespace character passes this simple validation, that's why you usually call trim() beforehand. And FYI, this is not a loop, this is an if statement.
Upvotes: 0
Reputation: 755
if your nameTextField
is empty then your validationBoolean
will be assigned as true.
if nameTextField
is not empty then a dialogue will occur with asking "Name", "Customer Name" and "Please enter name" and then the validationBoolean
will be assigned as false.
Upvotes: 0
Reputation: 26
if(!(nameTextField.getText()).equals(""))
If text of the nameTextField
is not blank ("") then it's valid. Else (if it's blank) it will prompt for Inputs
Upvotes: 1