Tom McFarlin
Tom McFarlin

Reputation: 829

OnClickListener vs. RelativeLayout.OnClickListener

I am following some tutorials for how to implement listeners, and find that some are using the RelativeLayout.OnClickListener and others just the OnClickListener. I haven't found any documentation explaining the difference between the two.

Is the method of RelativeLayout just altered to include additional functionality for layouts? What is the difference?

Upvotes: 0

Views: 282

Answers (2)

laalto
laalto

Reputation: 152827

For the purpose of view click listeners, there's only View.OnClickListener.

If you import the android.view.View.OnClickListener inner class, you can use it without specifying the outer View class.

If you specify a class that derives from View such as RelativeLayout, you can also use it to specify the inner class to use.

(There's also DialogInterface.OnClickListener but you use it only with dialogs.)

Upvotes: 2

Simon Marquis
Simon Marquis

Reputation: 7526

No, RelativeLayout.OnClickListener comes from View.OnClickListener as RelativeLayout extends View.

So you could use both, even though eclipse will maybe warn to to use the latter instead.

There is another OnClickListener: DialogInterface.OnClickListener used for Dialog

Upvotes: 0

Related Questions