committedandroider
committedandroider

Reputation: 9261

Difference between specifying the view.onclicklistener and just having onclicklistener

I looked on http://developer.android.com/reference/android/view/package-summary.html and saw that the view class has an interface named "View.OnClickListener" which is "Interface definition for a callback to be invoked when a view is clicked" My question is what the difference is if you specify the view or not in the interface?

Basically is

button.setOnClickListener(new Button.OnClickListener() the Same as

button.setOnClickListener(new OnClickListener()?

Upvotes: 1

Views: 1296

Answers (1)

Coderji
Coderji

Reputation: 7745

There are 2 of setOnClickListener one for the View class and one refer to DialogInterface Class.

So to in order to manipulate the View like a Button or ImageView and add an action to it, you need to use View.OnClickListener while dealing with Dialog buttons you should use DialogIneterface.onClickListener both have different arguments.

Usually by adding onClickListener, the View Class will be imported by default or it will make you choose between both classes. so you don't need to add View.onClickListener. However, if the class DialogInterface have been imported already and you want to use the View onClickListener then you have to write View.onClickListener to differentiate both classes' onClickListener.

Hope it is clear now and this is what you are looking for.

Upvotes: 4

Related Questions