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 Kotlin and Anko Adding the UI Finishing Touches

Please do help me ... i have watched the video again and again but cannot find the correct CODE

Fill in the blanks to create/add a TextView with a 'text' of "Treehouse" to the ViewManager.

For lambda expressions, leave one space after the left bracket and one space before the right bracket. E.g. { my lambda expression }.

ViewManager.ankoView(____, 0,____ )

2 Answers

Michael Nock
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Michael Nock
Android Development Techdegree Graduate 16,018 Points

This question is really tricky... So let's look at what ViewManager.ankoView() is asking for. There are three parameters:

  1. A lambda expression that takes in a context and returns a view (TextView in our case).
  2. The theme (we just use 0).
  3. An extension method to the view object which gets run before adding it to the ViewManager. This is essentially our init code.

So for the first blank, we need a lambda expression which takes in a context and outputs a view. Luckily enough, that's exactly what we need (a context) to create our TextView. Since we only have one argument getting passed in, we can shorten it to not need the variable declaration (ie. we don't need ctx ->) and just use the it keyword. I believe the test only accepts the version with it.

For the second blank, it's basically the same as the initialization lambda in the first few videos, only we don't need the "textView" part preceding it, only the lambda expression to set the text value to "Treehouse".

Does that clear things up any? I tried not to give too much away, if it's still not clear just let me know.

Tiger Wang
Tiger Wang
26,548 Points

Hey Tinashe:

Michael had provided such a nice steps to figure it out. I've stuck here for an hour. Finally, I try it out by following Michael suggestion. Like this:

ViewManager.ankoView({ TextView(it) } , 0 , { text = "Treehouse" })

Hope this can help. And I have to admit that sometimes lambda drives me crazy.