I have a method like:
public String get_Rid_something () {return((EditText)mParent.findViewById(Rid_something)).getText().toString();}
If there is no text in the EditText box, what happens, will there be an exception? Or will toString() just return the null for the string without an exception?
I have a bunch of these, so I’d like to efficiently fix each one so that they would return “0” if the text is null – hopefully without bracketing it with a try…catch construct.
Is there an “if” statement I could put in there to see if the string is null and return “0” if it is? Could I do something like:
if (((EditText)mParent.findViewById(Rid_something)).getText().toString().isEmpty()) {
return "0"; } else {...}
Any other suggestion of a better way to do this?
TIA!
If the EditText has no contents, it will return a blank string, or a “” In order to return with 0, simply set up an if statement:
This will return 0 if blank, or the contents if not.