【发布时间】:2021-01-06 20:00:19
【问题描述】:
Button myButton = (Button) findViewById(R.id. my_button)
据我所知,在 java 中所有代码都必须在类体上,也就是说,如果我们调用一个方法,我们必须通过对象调用它,或者如果它是静态方法,则通过其类名,如 bla.findViewByID(somemoreblass)
但在 android studio 我看到了这个Button myButton = (Button) findViewById(R.id. my_button)
谁能解释它是如何工作的?
【问题讨论】:
-
findViewById是声明mybutton的类的静态方法,或者它是 import static -
这个用户名很酷
-
@aran 我想是的
-
@fantaghirocco 你的意思是它是 Button 类的静态方法吗?抱歉,我在 rn,所以无法将 Button 突出显示为代码
标签: java android-studio