JakeWharton / butterknife

Bind Android views and callbacks to fields and methods.
http://jakewharton.github.io/butterknife/
Apache License 2.0
25.55k stars 4.6k forks source link

How to Use ButterKnife.bind() in a non activity class #694

Closed kaustav07 closed 8 years ago

kaustav07 commented 8 years ago

I am using a class that implements TextWatcher to validate my fields in Sign up page and i want to use butterknife to bind views. How can i do it. I have passed the instance of my Activity class to my TextWatcher implementation but after that also it doesn't bind the views..What can i do?

butterknife

And the call from Activity

butterknife2

JakeWharton commented 8 years ago

Use the two argument version which separates the instance being bound (this) from the source of the views (activity).

kaustav07 commented 8 years ago

In my code how to do that?Can you guide please?

egor-n commented 8 years ago

Call ButterKnife.bind(this, this.activity) instead of ButterKnife.bind(this.activity) in the SignUpValidation. The first argument is the target for your bindings, the second argument is the source of the bindings.

kaustav07 commented 8 years ago

It worked fine..Thank you very much..

eddieberklee commented 7 years ago

Sorry for resurfacing this old thread, but in the new version of ButterKnife, there is now the ability to bind resources, such as with @BindColor() - is this possible to do in a custom view as long as I have a context object. I know I can pass along my activity reference, but I'd just rather not add an unnecessary extra parameter.

JakeWharton commented 7 years ago

Yes. Reference the generated class directly and it has a constructor that accepts only a Context.

On Wed, Feb 22, 2017, 8:38 PM Edward Lee notifications@github.com wrote:

Sorry for resurfacing this old thread, but in the new version of ButterKnife, there is now the ability to bind resources, such as with @BindColor() - is this possible to do in a custom view as long as I have a context object. I know I can pass along my activity reference, but I'd just rather not add an unnecessary extra parameter.

— You are receiving this because you modified the open/close state.

Reply to this email directly, view it on GitHub https://github.com/JakeWharton/butterknife/issues/694#issuecomment-281863312, or mute the thread https://github.com/notifications/unsubscribe-auth/AAEEES57BvTdJzFJjgF3zDBvv_f4quqSks5rfOMfgaJpZM4JYz6e .

eddieberklee commented 7 years ago

Hi @JakeWharton thanks for the quick reply. I'm not sure what you mean by the generated class. Which class should I be looking at because ButterKnife.bind doesn't have a signature that accepts only a Context:

screenshot 2017-02-22 20 27 05

JakeWharton commented 7 years ago

SideScroller_ViewBinder

On Wed, Feb 22, 2017 at 11:28 PM Edward Lee notifications@github.com wrote:

Hi @JakeWharton https://github.com/JakeWharton thanks for the quick reply. I'm not sure what you mean by the generated class. Which class should I be looking at because ButterKnife.bind doesn't have a signature that accepts only a Context:

[image: screenshot 2017-02-22 20 27 05] https://cloud.githubusercontent.com/assets/1836653/23244923/6ddb8b48-f93d-11e6-963e-68242aadf5ef.png

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/JakeWharton/butterknife/issues/694#issuecomment-281891538, or mute the thread https://github.com/notifications/unsubscribe-auth/AAEEEfgUm1pOCz6-Ag_e0eNJ6hHGDHrTks5rfQregaJpZM4JYz6e .

eddieberklee commented 7 years ago

Oh shit. Thanks for making this library and helping me make my code a little cleaner.