i have 2 edit Text in my application, 1 button to add the input numbers in the edit Text and 1 text view to display the result. I would like to put a toast message if my edit te
You can try this two function for string empty, not empty or null. It is simple return true or false. It is very use for all projects.
if(isEmpty(edittext.getText().toString())){
// your Toast message if string is empty
}
if(isNotEmpty(edittext.getText().toString())){
// your Toast message if string is not empty
}
public static boolean isEmpty(String str) {
if (str == null)
return true;
else if (str.toString().trim().length() == 0)
return true;
return false;
}
public static boolean isNotEmpty(String str) {
if (str == null)
return false;
else if (str.toString().trim().length() == 0)
return false;
return true;
}