Hello everyone, I am new tho this forums and also new to android developing. what I am trying to accomplish at the moment is to check for validation on the form (if user added name lastname and age) then check if the user added correct age older than 4 younger than 80 (example numbers) . I made a small code about it but I am sure i am making some mistakes since whenever i press the button it crushes here is the entire button code
Code:
public void onSaveClick(View v) {
//check for valitation for Text
EditText name = (EditText) findViewById(R.id.nametxt);
EditText lname = (EditText) findViewById(R.id.lnametxt);
EditText age = (EditText) findViewById(R.id.agetxt);
String nameischecked = name.getText().toString();
String lnameischecked = lname.getText().toString();
String ageischecked = age.getText().toString();
final String checkage = age.getText().toString();
int value = Integer.parseInt(checkage);
Toast toast = null ;
if (nameischecked.matches("")) {
if (toast == null || toast.getView().getWindowVisibility() != View.VISIBLE ) {
toast = Toast.makeText(getApplicationContext(), "You Must Enter A Name !! ", Toast.LENGTH_SHORT);
toast.show();
toast = null;
return;
}
}
else if(lnameischecked.matches("")) {
if (toast == null || toast.getView().getWindowVisibility() != View.VISIBLE) {
toast = toast.makeText(getApplicationContext(),"You Must Enter A Lanename !! " , Toast.LENGTH_SHORT);
toast.show();
toast = null;
return;
}
}
else if(ageischecked.matches("")) {
if (toast == null || toast.getView().getWindowVisibility() != View.VISIBLE) {
toast = toast.makeText(getApplicationContext(),"You Must Enter An Age !! " , Toast.LENGTH_SHORT);
toast.show();
toast = null;
return;
}
}
else if(4 >= value || value >= 80) {
if (toast == null || toast.getView().getWindowVisibility() != View.VISIBLE) {
toast = toast.makeText(getApplicationContext(), "The Ages Must be from 4 to 80 ", Toast.LENGTH_SHORT);
toast.show();
toast = null;
return;
}
}
else {
Button savebtn = (Button) findViewById(R.id.button);
Button editbtn = (Button) findViewById(R.id.button2);
Button servbtn = (Button) findViewById(R.id.button3);
savebtn.setEnabled(false);
name.setEnabled(false);
lname.setEnabled(false);
age.setEnabled(false);
}
}