-12

Why does not

String.valueOf(edittext var name)

retrieve the text from EditText?

Phantômaxx
  • 37,352
  • 21
  • 80
  • 110
  • 1
    you should use edittext.getText().toString(); to retrieve text form EditText. If you want to show text inside EditText you should use edittext.setText("something"); . I think this will solve your problem. – Pasindu Weerakoon Jul 27 '18 at 10:33

3 Answers3

1

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.

Khemraj Sharma
  • 52,662
  • 21
  • 188
  • 195
0

Use editTextName.getText().toString() which returns String value

AskNilesh
  • 63,753
  • 16
  • 113
  • 150
Mukesh Shakya
  • 417
  • 3
  • 9
0
String value = String.valueOf(editText.getText())
Ticherhaz FreePalestine
  • 2,183
  • 4
  • 18
  • 42