Difference between OnClick() event and OnClickListener?

后端 未结 16 2454
醉话见心
醉话见心 2020-12-01 12:13

I\'m always using onclick() event in most of my projects. But, I read about OnClickListener(). Can anyone tell what\'s the difference between these

16条回答
  •  北荒
    北荒 (楼主)
    2020-12-01 13:15

    OnClickListener is the interface you need to implement and can be set to a view in java code.

    Lately android added a xml attribute to views called android:onclick, that can be used to handle clicks directly in the view's activity without need to implement any interface.

    Both function the same way, just that one gets set through java code and the other through xml code.

提交回复
热议问题