[英]OnClick ButterKnife, nothing happens
I'm trying to use ButterKnife to onClick. 我正在尝试使用ButterKnife来onClick。 I did the code bellow and nothing happens, I've watched tutorials all over the internet, and they do the same thing as I did.
我没有执行下面的代码,什么也没发生,我已经在互联网上观看了所有教程,它们的工作方式与我相同。
Here is the code 这是代码
@BindView(R.id.startButton) protected ImageButton mStartButton;
@OnClick(R.id.startButton)
public void startTest(){
Toast.makeText(this, "testing", Toast.LENGTH_LONG).show();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(MainActivity.this);
}
And if I put the method startTest(); 如果我把方法startTest(); inside the OnCreate, the toast is called when the app runs for the first time, what shows that the ButterKnife is working.
在OnCreate内部,当应用程序首次运行时会调用Toast,这表明ButterKnife正在运行。 But I need that to happen only when the button is clicked.
但是我需要仅在单击按钮时才发生这种情况。
Thanks 谢谢
You mentioned that you have compile 'com.jakewharton:butterknife:8.4.0'
in your build.gradle
file. 您提到您已经在
build.gradle
文件中compile 'com.jakewharton:butterknife:8.4.0'
。 I think you may be missing the corresponding compiler. 我认为您可能缺少相应的编译器。 Add this to your
dependencies
section: 将此添加到您的
dependencies
部分:
annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
The only two reason i can see are either 我能看到的唯一两个原因是
or 要么
I think your onCreate method should be public. 我认为您的onCreate方法应该是公开的。 Try it.
试试吧。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.