Difference between specifying the view.onclicklistener and just having onclicklistener

旧城冷巷雨未停 提交于 2019-12-11 07:58:33

问题


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()?


回答1:


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.



来源:https://stackoverflow.com/questions/24421330/difference-between-specifying-the-view-onclicklistener-and-just-having-onclickli

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!