Very basic Android Studio question:
How do I activate that Toast?
Normally, if I type in anything in Android Studio, I get a list of code I can Alt+Enter on / click on and it implements it. How do I implement that in the attached picture? so it looks like this:
I clicked the buttons that normally would implement stuff like Alt+Enter but that doesn’t seem to be working. How do I get that second image from that first image?
2
Answers
The bracket is the scope of the on click listener which has the view so it always there. There is no difference between the two images you have aside from the brackets being expanded out. The
it
is of typeView
and always going to beview
in the case. This is a lambda so there is nothing else you need to "implement", this is the callback for the button click. Notice how onClick gives you the view as a parameter? This is exactly the same thing just less verboseExample:
is the same as
And all are the same as the more verbose way
Doing it the last way, Android Studio will suggest that you do the other ways anyway
Position your caret next to the first curly bracket
{
, then press Alt+Enter/Option+Enter, this will open up this menu, select the "Enable option ‘Implicit receivers and parameters’ for ‘Lambdas’ inlay hints".