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 Coding an Options Menu

Understanding the code

Hello, I was checking the documentation and I realized Menu was an interface, so in which class is it implemented on the following code??:

@Override public boolean onCreateOptionsMenu(Menu menu) { MenuItem menuItem = menu.add("Next Image"); (...)

1 Answer

Ben Deitch
STAFF
Ben Deitch
Treehouse Teacher

Hey Tomas! It would be implemented by the 'menu' being passed into 'onCreateOptionsMenu'.

For example, if we had an interface that required a keyboard, we could have a method like: doSomething(Keyboard keyboard) And we could pass in objects that implement our keyboard interface like doSomething(phone) or doSomething(laptop).

So we're not entirely sure what class is being passed into 'onCreateOptionsMenu'. We just know that, whatever class it is, it definitely implements the Menu interface.

I understand now, thanks a lot! :)