How exactly does the android:onClick XML attribute differ from setOnClickListener?

后端 未结 17 2119
野趣味
野趣味 2020-11-21 11:50

From that I\'ve read you can assign a onClick handler to a button in two ways.

Using the android:onClick XML attribute where you just use t

17条回答
  •  感情败类
    2020-11-21 12:25

    When I saw the top answer, it made me realize that my problem was not putting the parameter (View v) on the fancy method:

    public void myFancyMethod(View v) {}
    

    When trying to access it from the xml, one should use

    android:onClick="myFancyMethod"/>
    

    Hope that helps someone.

提交回复
热议问题