I am learning how to create UI elements. I have created a few EditText input fields. On the click of a Button I want to capture the content typed into that input field.
<EditText android:id="@+id/name" android:width="220px" />
That's my field. How can I get the content?
You might also want to take a look at Butter Knife. It aims at reducing the amount of boilerplate code by using annotation. Here is a simple example:
Just add the following dependency to your
build.gradle
:As an alternative there is also AndroidAnnotations.
Get value from an
EditText
control in android.EditText
getText
property use to get value anEditText
:Try this code
By using getText():
I like shortcuts, so I do this.
Just make method in your BaseActivity / create BaseActivity if you don't have.
And extend your all activities by this BaseActivity.
Note that
EditText
,Button
extendsTextView
, so I created onlygetText(TextView tv)
.