Just came across butterknife recently. I added the line in my gradle(module : app) file: compile 'com.jakewharton:butterknife:7.0.1'
最近刚遇到黄油刀。我在我的gradle(模块:app)文件中添加了一行:编译'com.jakewharton:butterknife:7.0.1'
It synched without any errors. I'm able to import 'butterknife.Butterknife' to my class file where the imports usualyy go. But cant import butterknife.InjectView doesn't seem to be there? Any suggestions?
它同步没有任何错误。我能进口“黄油刀”。黄油刀,到我的类文件,进口通常去那里。但不能导入butterknife。InjectView似乎不存在?有什么建议吗?
3 个解决方案
#1
5
The Butterknife 7.0.0 release included the breaking change of renaming of the annotation verbs. This is highlighted in the changelog and reflected in the website.
Butterknife 7.0.0发行版包含重命名注释谓词的破坏性更改。在changelog中突出显示了这一点,并反映在网站中。
Version 7.0.0 *(2015-06-27)*
----------------------------
* `@Bind` replaces `@InjectView` and `@InjectViews`.
* `ButterKnife.bind` and `ButterKnife.unbind` replaces `ButterKnife.inject`
and `ButterKnife.reset`, respectively.
...
https://github.com/JakeWharton/butterknife/blob/f65dc849d80f6761d1b4a475626c568b2de883d9/CHANGELOG.md
A very good, and up-to-date, introduction to the usage is at http://jakewharton.github.io/butterknife/
关于这个用法的一个非常好的最新介绍是http://jakewharton.github.io/butterknife/
Here is the simplest usage:
下面是最简单的用法:
class ExampleActivity extends Activity {
@Bind(R.id.title) TextView title;
@Bind(R.id.subtitle) TextView subtitle;
@Bind(R.id.footer) TextView footer;
@Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.simple_activity);
ButterKnife.bind(this);
// TODO Use fields...
}
}
#2
3
Obviously @InjectView
was replaced by @Bind
.
显然,@InjectView被@Bind取代。
Furhtermore you have to call ButterKnife.bind(this);
in your onCreate()
.
你必须叫它ButterKnife.bind(这个);在onCreate()。
see: http://jakewharton.github.io/butterknife/
参见:http://jakewharton.github.io/butterknife/
#3
3
@InjectView
is no more available and is replaced by @BindView
. We will have to import Butterknife
dependencies to use the annotations. More on butter knife here :- http://jakewharton.github.io/butterknife/
@InjectView不再可用,取而代之的是@BindView。我们将不得不导入Butterknife依赖项来使用注释。更多关于黄油刀的信息请访问:http://jakewharton.github.io/butterknife/
@BindView
annotation could be implemented as :-
@BindView注释可以实现为:-
@BindView(R.id.button_id)
Note that you will need to call ButterKnife.bind(this);
from onCreate()
method of the main activity to enable Butterknife annotations. An example on this implementation could be something like :-
注意,您需要调用ButterKnife.bind(这个);来自onCreate()方法的主要活动,以启用Butterknife注释。这个实现的一个例子可以是:-
public class MainActivity extends AppCompatibilityActivity{
@BindView(R.id.editText_main_firstName)
EditText firstName;
@BindView(R.id.editText_main_lastName)
EditText lastName;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Needs to be called to enable Butterknife annotations
ButterKnife.bind(this);
}
}
#1
5
The Butterknife 7.0.0 release included the breaking change of renaming of the annotation verbs. This is highlighted in the changelog and reflected in the website.
Butterknife 7.0.0发行版包含重命名注释谓词的破坏性更改。在changelog中突出显示了这一点,并反映在网站中。
Version 7.0.0 *(2015-06-27)*
----------------------------
* `@Bind` replaces `@InjectView` and `@InjectViews`.
* `ButterKnife.bind` and `ButterKnife.unbind` replaces `ButterKnife.inject`
and `ButterKnife.reset`, respectively.
...
https://github.com/JakeWharton/butterknife/blob/f65dc849d80f6761d1b4a475626c568b2de883d9/CHANGELOG.md
A very good, and up-to-date, introduction to the usage is at http://jakewharton.github.io/butterknife/
关于这个用法的一个非常好的最新介绍是http://jakewharton.github.io/butterknife/
Here is the simplest usage:
下面是最简单的用法:
class ExampleActivity extends Activity {
@Bind(R.id.title) TextView title;
@Bind(R.id.subtitle) TextView subtitle;
@Bind(R.id.footer) TextView footer;
@Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.simple_activity);
ButterKnife.bind(this);
// TODO Use fields...
}
}
#2
3
Obviously @InjectView
was replaced by @Bind
.
显然,@InjectView被@Bind取代。
Furhtermore you have to call ButterKnife.bind(this);
in your onCreate()
.
你必须叫它ButterKnife.bind(这个);在onCreate()。
see: http://jakewharton.github.io/butterknife/
参见:http://jakewharton.github.io/butterknife/
#3
3
@InjectView
is no more available and is replaced by @BindView
. We will have to import Butterknife
dependencies to use the annotations. More on butter knife here :- http://jakewharton.github.io/butterknife/
@InjectView不再可用,取而代之的是@BindView。我们将不得不导入Butterknife依赖项来使用注释。更多关于黄油刀的信息请访问:http://jakewharton.github.io/butterknife/
@BindView
annotation could be implemented as :-
@BindView注释可以实现为:-
@BindView(R.id.button_id)
Note that you will need to call ButterKnife.bind(this);
from onCreate()
method of the main activity to enable Butterknife annotations. An example on this implementation could be something like :-
注意,您需要调用ButterKnife.bind(这个);来自onCreate()方法的主要活动,以启用Butterknife注释。这个实现的一个例子可以是:-
public class MainActivity extends AppCompatibilityActivity{
@BindView(R.id.editText_main_firstName)
EditText firstName;
@BindView(R.id.editText_main_lastName)
EditText lastName;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Needs to be called to enable Butterknife annotations
ButterKnife.bind(this);
}
}