How to implement OnClickListener on Android

前端 未结 5 645
眼角桃花
眼角桃花 2021-01-06 16:26

I learn from

http://developer.android.com/reference/android/widget/Button.html

that \"instead of applying an OnClickListener to the button

5条回答
  •  臣服心动
    2021-01-06 17:13

    I've explained the different ways you can implement an OnClickListener on my blog: http://www.androiddevresources.com/guides/tutorial-how-to-implement-an-onclicklistener/

    Basically there are three ways. - Implement the listener in the activity class (and set the xml attribute) - Create a variable in your activity class (or other class, for example a fragment). - Create a new listener in line with new OnClickListener().

    I've added example code in the article and an example project on GitHub which you can download.

提交回复
热议问题