I haven't quite figured out the preferred way to setup listeners in android. I tend to set up my listeners like this:
(First way)
myButton.setOnClickListener(this);
as opposed to
(Second Way)
myButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//handle clicks
}
});
However I recently came across this question where one of the comments said:
...use of a smaller class to act as the listener interface vs passing the whole adapter to act as the interface.
To my understanding, inner classes have an implicit reference to the outer one so depending on how you set up the listener should have no affect on what object is passed in/referred.
Can some one clarify which is the better way and why? Is using this
(First Way) more expensive than having an anonymous inner class (Second Way)?