gpt4 book ai didi

java - View的android :onClick as static method,可能吗?

转载 作者:搜寻专家 更新时间:2023-11-01 08:02:59 24 4
gpt4 key购买 nike

如文档所述

Name of the method in this View's context to invoke when the view is clicked.

完美,但是否可以“以某种方式”创建静态方法并在我需要的任何地方使用它,而不是在每个 Activity 类中定义。是的,我知道在 Activity 基类中定义方法。我正在寻找的只是写下方法的全名并让它使用它。可能吗?

谢谢

最佳答案

您不能将静态方法分配给 onClick xml 属性。您必须将您在此处指定的方法添加到使用布局的任何 Activity 。您可以让每个 Activity 中的该方法调用一个实际处理点击的静态方法,但无法避免完全使用实例方法。

关于java - View的android :onClick as static method,可能吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18398678/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com