Ben Rogers6,668 Points
I can't figure this question out. It looks like very different code than the one in the tutorial
I've been stuck on this for a while. I'm not entirely sure what is being asked of me.
EditText petNameField = (EditText)findViewById(R.id.petNameField); String petName;
Rebecca RichPro Student 8,587 Points
Somewhere in an .xml file there is an
EditText component with the ID
petNameField. The first line of this sample code creates a reference to the
EditText component, which is an editable text extension of
TextView. Here is more information about
When you have
petNameField as a reference to the
EditText in the view, you simple have a reference to the view component, not the actual text entered into that view by a user. The goal of the challenge is to get the text entered into the
EditText by a user and store it as a String,
petname. To do so, we need to call a method on
petNameField. If you look at the list of public methods on the link above, you will find the
getText() - a method described to be able to "Return the text that TextView is displaying." This looks like a great fit, but only returns an
Editable, so we will also have to call
getString(). Altogether, we will need:
String petName = petNameField.getText().toString();
to get the pet name from the pet name field.
Does this help?