One OnClickHandler for multiple Buttons

后端 未结 6 2099
再見小時候
再見小時候 2020-11-28 23:09

I find myself doing things like this all the time:

    Button button1 = (Button) findViewById(R.id.button1);
    Button button2 = (Button) findViewById(R.id.         


        
6条回答
  •  情书的邮戳
    2020-11-29 00:06

    You can also set it in your layout xml using the android:onclick attribute.

    android:onClick="onClick"
    

    Then in your activity class add the onClick method.

    public void onClick(View v) {
    ...
    

    Here's the documentation.

提交回复
热议问题