Eclipse and onClickListener


When I want to create an anon inner class with eclipse I start by typing new onClick…
This triggers eclipse to suggest View.onClickListener() and implements the interface with a stub. (aside: I’m new to java so please correct my vocabulary)

The Problem:
When I click the suggestion (it says View.onClickListener() ), eclipse sets it up as onClickListener() and not View.onClickListener(). This gives an error and I always have to add the View. in front. Can you describe what is going on and how to fix it?


I believe onClickListener may be a valid call in other cases and the auto complete is not smart enough to differentiate. I type “new View.” and then the auto complete suggests the onClickListener as the first (one of(?)) option for completion.


Thanks naven87! I’ll start typing View. from now on. I guess out of curiosity I would still like to know why when I click on what clearly looks like View.onClickListener() it changes it to just onClickListener()?


As far as I know this is just an annoyance of Eclipse’s autocomplete (or “Content Assist” as they call it) feature.

I typically type, as naven87 suggests, “new View.” and accept the first suggestion.

If you do just type OnClickListener, the reason it has a compiler error is because Eclipse for some reason doesn’t import that interface automatically. If you manually “organize imports” with ctrl/cmd+shift+O, it should add an import like: