![](/img/trans.png)
[英]Which method is called the first one if we have overriden methods in Java?
[英]In onClick Event in XML , we give a method name , in which java file does the document have to be in?
假设我们想让按钮做某事,我们可以使用onClick事件或onClickListener
在XML文件中使用onClick事件时,我们输入一个方法名称。 该方法必须位于何处?
在活动类中,XML布局被放大。
该签名必须public
:
public void doSomething(View v) {
//..........
}
在活动的xml中,设置为Button
的属性必须为:
android:onClick="doSomething"
v
参数实际上是触发此事件的View
,
在您的情况下为Button
,您可以通过以下方式访问它:
Button button = (Button) v;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.