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.
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:
public class ExampleActivity extends ActionBarActivity {
@InjectView(R.id.name)
EditText nameEditText;
@InjectView(R.id.email)
EditText emailEditText;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_example);
Butterknife.inject(this);
}
@OnClick(R.id.submit)
public void onSubmit() {
Editable name = nameEditText.getText();
Editable email = emailEditText.getText();
}
}
Just add the following dependency to your build.gradle:
compile 'com.jakewharton:butterknife:x.y.z'
As an alternative there is also AndroidAnnotations.