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

Sayed Hamza Ahmed
Sayed Hamza Ahmed
1,349 Points

Now that we have a model object, update the TextView to use the Spaceship's type property. Remember to use the helpful g

i am not understanding

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);

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


  public String getSpaceship(){
    return mSpaceship;
  }

    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;
    }
}

2 Answers

Christopher Augg
Christopher Augg
21,223 Points

Hello Sayed Hamza Ahmed.

You need to set your mTypeLabel TextView to the type of the spaceship object you created in task 1. Remeber, a TextView object has a setText method. Therefore, after the mSpaceship initialization, you want to call mTypeLabel.setText() and pass the mSpaceship.getType() method into it because it returns a String for the type.

Please let me know if this helps.

Regards,

Chris

Sayed Hamza Ahmed
Sayed Hamza Ahmed
1,349 Points

can you please show me on the work space it would help me a lot

Christopher Augg
Christopher Augg
21,223 Points

No problem.

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");
      mTypeLabel.setText(mSpaceship.getType());
      // taks 3 here: 
      // make a String variable and assign it the number of passengers using mSpaceship's getNumPassenger
      // method. Remember to use + "" with it so it will convert to String before assignment.

      // mPassengersField has a setText method. Call it here and pass the String variable you just made


    }
}

We see that mTypeLabel is assigned a TextView for you in the challenge. Therefore, you just need to use mTypeLabel.setText() to set its text to the type of the spaceship. The first task had you create a new Spaceship object and assign it to mSpaceship. This allows you to call mSpaceship's methods. When looking in the Spaceship class, we can see that it has the method getType() that returns a String. That is the String you want to pass into the mTypeLabel.setText() method. I have provided the solution within the code above for this task. However, please attempt task 3 as the concept is the same. I provided some hints for you as well. Let me know if you need further help and I will gladly go over it.

Regards,

Chris

Sayed Hamza Ahmed
Sayed Hamza Ahmed
1,349 Points

Thank you so much Chris thanks a lot :)

Will Macleod
Will Macleod
Courses Plus Student 18,780 Points

Thanks Chris, amazing explanation, I love how you didn't give the answer straight away.