-12

Why does not

String.valueOf(edittext var name)

retrieve the text from EditText?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
  • 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
  • 57,232
  • 27
  • 203
  • 212
0

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

AskNilesh
  • 67,701
  • 16
  • 123
  • 163
Mukesh Shakya
  • 425
  • 3
  • 9
0
String value = String.valueOf(editText.getText())
Ticherhaz FreePalestine
  • 2,738
  • 4
  • 20
  • 46