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 trialSayed Hamza Ahmed
1,349 PointsNow 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
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!
}
}
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
21,223 PointsHello 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
1,349 PointsThank you so much Chris thanks a lot :)
Will Macleod
Courses Plus Student 18,780 PointsThanks Chris, amazing explanation, I love how you didn't give the answer straight away.
Sayed Hamza Ahmed
1,349 PointsSayed Hamza Ahmed
1,349 Pointscan you please show me on the work space it would help me a lot
Christopher Augg
21,223 PointsChristopher Augg
21,223 PointsNo problem.
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