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 Formatting Strings

Need Help with Task 2 after this video

Hi Ben could you plese help as i can't seem to get past Tast 2?

l need help on the task 1

can you help on the task 1

3 Answers

Jeremy Faith
PLUS
Jeremy Faith
Courses Plus Student 56,696 Points

I have to assume this is the question you are asking about(Task 2 from Using a Model in the Controller).

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

You will need to set the text for the TextView mTypeLabel using mSpaceship's getType method provided. Your answer should look like this.

mTypeLabel.setText(mSpaceship.getType());

hue can you help me on the task 1 .l am failing to solve it

hie can you help me on the task 1 .l am failing to solve it

brandtvavasour
brandtvavasour
4,636 Points

I can't solve the third one -__-, any help?

Jeremy Faith
PLUS
Jeremy Faith
Courses Plus Student 56,696 Points

brandtvavasour, first you will need to call the setText method on mPassengersField.

mPassengersField.setText();

Inside setText, you need to get mSpaceship's number of passengers using constructor getNumPassengers(). Since the return value is an int need to convert to a string for the setText() method.

Integer.toString(mSpaceship.getNumPassengers())

Finally, you code should look like this.

mPassengersField.setText(Integer.toString(mSpaceship.getNumPassengers()));
brandtvavasour
brandtvavasour
4,636 Points

Thanks heaps Jeremy Faith!

Jeremy , thanks alot ! I have a follow up question , I cant recall we learned Integer.toString method .

how come : """ mPassengersField.setText(mSpaceship.getNumPassengers().toString()); """ does not work ? Is it wrong ?

Thank you very much Jeremy. Well as Ivan has pointed out since we have not learned the Integer.toString method, instead of the code

Integer.toString(mSpaceship.getNumPassengers())

We can use the code below

String.format("%s",mSpaceship.getNumPassengers())

Where ā€œ%sā€ would be the format specifier for String. Refer the Formatting String Syntax Documentation in the video to read more.

So our final code would be

mPassengersField.setText(String.format("%s",mSpaceship.getNumPassengers()));

Please do correct me if I am wrong. Thanks

Thank you