search

Home  >  Q&A  >  body text

Android中如何在布局文件中为组件绑定点击事件?

Android中如何在布局文件中为组件绑定点击事件?

阿神阿神2772 days ago438

reply all(1)I'll reply

  • 伊谢尔伦

    伊谢尔伦2017-04-17 17:40:21

    Add the onClick="name" attribute to the component in the layout file.
    The "name" can be arbitrary, as long as it corresponds to the class

    Then in the class
    public void name(View view) {

    System.out.println("我被点击了!");

    }

    Write your click logic in this function

    reply
    0
  • Cancelreply