How to set text entered in Android Studio 'EditText' to a variable?

My question is very simple, but I can not understand it. I have an application that allows users to enter a value in the EditText field. I need to create a String variable that stores this input. It must be a String variable using findViewById does not work. I don’t understand why I can’t find a solution, so if you could help!

Drew

+7
source share
2 answers

Like this

// get EditText by id and store it into "inputTxt" EditText inputTxt = (EditText) findViewById(R.id.input); // Store EditText - Input in variable String typedText = inputTxt.getText().toString(); 
+16
source

use your_edit_box.getText (). toString () to get the text entered in the edit box. Maybe it is useful

Get the value of the text edit field

+1
source

All Articles