Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Build an Interactive Story App (Retired) Finishing the User Interface Using a Model in the Controller

Michael LaCroix
Michael LaCroix
5,828 Points

Update Textiew to use object's property

I'm a little confused and a little stuck. I'm confused because I'm not exactly sure what the directions are asking me to do. What does it mean by update the TextView & how do I do that? I don't understand what the TextView is doing in the first place so that might add to my confusion as to fixing or updating something that I don't understand to begin with. And does it want me to use type property in terms of () or the actual name ("FIREFLY")?

LandingActivity.java
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class LandingActivity extends Activity {

    public Button mThrustButton;
    public TextView mTypeLabel;
    public EditText mPassengersField;

    public Spaceship mSpaceship;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_landing);

        mThrustButton = (Button)findViewById(R.id.thrustButton);
        mTypeLabel = (TextView)findViewById(R.id.typeTextView);
        mPassengersField = (EditText)findViewById(R.id.passengersEditText);

        // Add your code here!
      mSpaceship = new Spaceship("FIREFLY");
      TextView = getSpaceship{
        return this.Spaceship();
      }
    }
}
Spaceship.java
public class Spaceship {
    private String mType;
    private int mNumPassengers = 0;

    public String getType() {
      return mType;
    }

    public void setType(String type) {
      mType = type;
    }

    public int getNumPassengers() {
      return mNumPassengers;
    }

    public void setNumPassengers(int numPassengers) {
      mNumPassengers = numPassengers;
    }

    public Spaceship() {
      mType = "SHUTTLE";
    }

    public Spaceship(String type) {
      mType = type;
    }
}
Michael LaCroix
Michael LaCroix
5,828 Points

Tried this

TextView = mTypeLabel.getText();

But for some reason I'm getting an error that it doesn't recognize TextView anymore. Now I'm really confused...

2 Answers

Chris Casey
Chris Casey
11,656 Points

Not 100% sure what the directions are without seeing them posted but you can try this:

mSpaceship = new Spaceship("FIREFLY"); mTypeLabel.setText(mSpaceship.getType());

luis martinez
luis martinez
2,480 Points

i have a question. why don't you do

mTypeLabel.setText(mSpaceship.getText());

Michael LaCroix
Michael LaCroix
5,828 Points

Ugh. Thanks. There are so many different potential commands and I'm just lost trying to remember half of them.

Chris Casey
Chris Casey
11,656 Points

Lol, I hear ya. Try not to get overwhelmed. It all looks like hieroglyphics at first, but you'll get more comfortable over time. Just keep at it.