I am new to android development. I am learning android development given here their is a piece of code
Intent intent = new Intent(this, DisplayMessageActivity.class);
EditText editText = (EditText) findViewById(R.id.edit_message);
String message = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);
I want to know why we use String message = editText.getText().toString() after using EditText editText = (EditText) findViewById(R.id.edit_message); What does EditText return?
Edittext returns text which is entered by user which is in editable form after getting editable object you can convert editable to string using below code and store into string variable.
As we all know that EditText is a space where user can write or type anything and that content has been stored in a string format. So to get the content from user and to store them we use this
String message = editText.getText().toString()
the getText() method get the content inside editText and toString() will convert it to string format.The getText() method of EditText returns a object of Editable, not String (to retrieve the text of EditText, toString() of Editable can be used.).
This line is for is like getting a
reference
to the Textview.By using reference only u can do whatever functionality on that textview.This line after getting reference your are setting the Text to that Textview(using that reference).
Also one more suggestion GOOGLE for android basics..
it is converting your xml edit text into java EditText. After doing this one only you can access your xml EditText by using the
Here we are getting the id of
EditText
for getting the value which you have entered inEditText
..and to store that value we are using
I hope you got you answer...