问题描述
我正在尝试为Android创建应用,我按照本教程
I'm trying to create an app for Android, and I follow this tutorial http://developer.android.com/training/basics/firstapp/starting-activity.html
有一部分
/** Called when the user clicks the Send button */
public void sendMessage(View view) {
// Do something in response to button
}
然后我按照本教程一切正常,直到我删除参数查看视图
then I followed this tutorial and everything worked, untill I remove parameter View view
我的问题就是为什么每次我删除它,所以函数只是:
my question is just why everytime I remove it, so the function just be:
/** Called when the user clicks the Send button */
public void sendMessage() {
// Do something in response to button
}
我运行应用程序,强制关闭。
and I run the app, it forced close.
任何人都可以开导我吗?谢谢
could anyone enlighten me? thank you
推荐答案
该方法(通常称为 onClick(查看视图)
)方法接受一个参数(与之关联的视图)。请参阅有关该功能的更多信息。如果你放弃参数,你不会期望它起作用,不是吗?
the method (typically called onClick(View view)
) method takes a parameter (the View it is associated with). see http://developer.android.com/reference/android/view/View.OnClickListener.html for more information on the function. if you leave off the parameter you wouldn't expect it to work, would you?
这篇关于将View类对象作为参数传递给按钮调用的方法(View视图)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!