Why does not
String.valueOf(edittext var name)
retrieve the text from EditText
?
Why does not
String.valueOf(edittext var name)
retrieve the text from EditText
?
That's what Android has provided.
You can just use editText.getText().toString()
instead.
Info about String.valueOf(obj)
String
class is a Java class, it does not know Android classes like TextView
or EditText
.String.valueOf
accept EditText
or any object because it will be considered to call String.valueOf(Object)
method. From String Documentation internal implementation of String.valueOf(Object)
is
public static String valueOf(Object obj) {
return (obj == null) ? "null" : obj.toString();
}
If you call String.valueOf(editText)
It will return you class name like EditText@2a139a55
.
Use editTextName.getText().toString()
which returns String value