Menu

I recently wrote a couple of Android apps in the native Java language. One of the things I hated about this was the amount of boilerplate. First, I would create a UI element and give it an ID – something like:

That’s a lot of necessary boilerplate code and it obscures the real work that onCreate() is doing. Fortunately, someone else thought of this as well. A guy by the name of Jake Wharton, in fact. This was obviously such a big deal for him that he wrote a library for it called ButterKnife.

So, how does this library change things? Well, let’s take my example above. I have a city field in the UI – I’m not going to get rid of that. Then I have a private variable within the class. Finally, I want to do all the bindings at once. This is what my MainActivity class would look like with the new semantics: