Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between bind and injectView in butterknife

I am using butterknife library. I don't know much about how to use it. I found injectView and bind doing the same thing but I am not really sure. Can anyone explain the difference between these two.

like image 203
Rookie Avatar asked Feb 01 '16 04:02

Rookie


People also ask

What is ButterKnife bind?

Butterknife is a light weight library to inject views into Android components. It uses annotation processing. The @BindView annotation allow to inject views and performs the cast to the correct type for you. The @@OnClick(R. id.

How do I replace ButterKnife with view binding?

Enable View Binding in the build. The first change was to remove all Butterknife dependencies in our Android project. In order for us to use view binding, we had to enable it within the build. gradle(app) file. Once viewBinding has been enabled, let's sync our project!

What is ButterKnife dependency injection?

Android ButterKnife library is a view injection library that injects views into android activity / fragments using annotations. For example, @BindView annotation avoids using findViewById()method by automatically type casting the view element.


2 Answers

Can anyone explain the difference between these two ?

@InjectView was changed to @Bind .

Annotate fields with @Bind and a view ID for Butter Knife to find and automatically cast the corresponding view in your layout.

class YourActivity extends Activity {
  @Bind(R.id.TvTitle) TextView title;

Please check below links. Hope this helps .

  1. JakeWharton Butterknife
  2. The import butterknife.InjectView cannot be resolved

  3. Introduction Butter Knife

GRADLE

compile 'com.jakewharton:butterknife:7.0.1' //8.4.0 

https://github.com/JakeWharton/butterknife/blob/f65dc849d80f6761d1b4a475626c568b2de883d9/CHANGELOG.md

like image 191
IntelliJ Amiya Avatar answered Nov 10 '22 02:11

IntelliJ Amiya


If I'm not mistaken, they have the same function. There was a change in naming convention starting version 7 of butterknife, injectView was changed to bind.

Check the changelog, also check this issue.

Check this link: How to use butterknife

like image 44
hehe Avatar answered Nov 10 '22 04:11

hehe