I have an EditText in android for users to input their AGE. It is set an inputType=phone. I would like to know if there is a way to check if this EditText is null.
I've already looked at this question: Check if EditText is empty. but it does not address the case where inputType=phone.
These, I've checked already and do not work:
(EditText) findViewByID(R.id.age)).getText().toString() == null
(EditText) findViewByID(R.id.age)).getText().toString() == ""
(EditText) findViewByID(R.id.age)).getText().toString().matches("")
(EditText) findViewByID(R.id.age)).getText().toString().equals("")
(EditText) findViewByID(R.id.age)).getText().toString().equals(null)
(EditText) findViewByID(R.id.age)).getText().toString().trim().length() == 0
(EditText) findViewByID(R.id.age)).getText().toString().trim().equals("")
and isEmpty do not check for blank space.
Thank you for your help.
editText.length() usually works for me try this one
Simply do the following
Try this. This is the only solution i got
String phone;
try{ phone=(EditText) findViewByID(R.id.age)).getText().toString();
} catch(NumberFormatException e){
Toast.makeText(MainActivity.this, "plz enterphone Number ", Toast.LENGTH_SHORT).show(); return;
}