简体   繁体   English

@OnClick在Butterknife上不起作用

[英]@OnClick on Butterknife doesn't work

There is no error in code or gradle build but when I click to button, nothing happens 代码或gradle构建中没有错误,但是当我单击按钮时,什么也没有发生

@BindView(R.id.bWakeup) Button bWakeup;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ButterKnife.bind(this);


}

@OnClick(R.id.bWakeup)
public void wakeButtonClick(View v) {
    Intent intent = new Intent(MainActivity.this, SetTimeActivity.class);
    intent.putExtra(MODE, WAKEUP);
    startActivity(intent);
}

Edited: Configuration is more simple now. 编辑:配置现在更加简单。

I Followed below-given step and its working fine for me. 我遵循了下面给出的步骤,它对我来说很好。

Add the below Butter Knife dependencies: 添加以下黄油刀依赖性:

apply plugin: 'com.android.library'

android {
          ...
        }
dependencies {
              compile 'com.jakewharton:butterknife:8.8.1'
              annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
        }

If you are using Kotlin, replace annotationProcessor with kapt. 如果您使用的是Kotlin,请用kapt替换注释处理程序。

For more refer 欲了解更多请参考

For single button you will not get view object so just remove it and check 对于单个按钮,您将不会获得视图对象,因此只需将其删除并检查

example

@OnClick(R.id.bWakeup)
public void onClick() {}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM