Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![sai maddukuri](https://secure.gravatar.com/avatar/83328f1bb0aaac22a1b5706a3a5f0fd3?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
sai maddukuri
9,108 Pointsi cant understand why we included ButterKnife.bind(AlbumDetailActivity.this);
you used ButterKnife api but i can't understand the purpose of ButterKnife.bind(AlbumDetailActivity.this); can any one help? i can't understand !!!! or can any one tell the replacement code for ButterKnife.bind(AlbumDetailActivity.this); i mean without api!!!!
1 Answer
![Lauren Moineau](https://secure.gravatar.com/avatar/85610a2dbe7e46c1f8069977ed981d5b?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Lauren Moineau
9,483 PointsHi Sai. Butterknife.bind()
is called to bind the data to the views of the activity passed into the method (in your example, AlbumDetailActivity.java
). It replaces the usual findViewbyId()
calls, making the code more concise as you only need one call.
Without the Butterknife library, your code would be:
public class AlbumDetailActivity extends AppCompatActivity {
ImageView albumArtView;
ImageButton fab;
ViewGroup titlePanel;
ViewGroup trackPanel;
ViewGroup detailContainer;
// (...)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_album_detail);
albumArtView = findViewById(R.id.album_art);
fab = findViewById(R.id.fab);
titlePanel = findViewById(R.id.title_panel);
trackPanel= findViewById(R.id.track_panel);
detailContaine= findViewById(R.id.detail_container);
// (...)
}
}
With the Butterknife library:
public class AlbumDetailActivity extends AppCompatActivity {
@BindView(R.id.album_art) ImageView albumArtView;
@BindView(R.id.fab) ImageButton fab;
@BindView(R.id.title_panel) ViewGroup titlePanel;
@BindView(R.id.track_panel) ViewGroup trackPanel;
@BindView(R.id.detail_container) ViewGroup detailContainer;
// (...)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_album_detail);
ButterKnife.bind(this);
// (...)
}
}
Hope that helps :)
Ryan Dsouza
9,388 PointsRyan Dsouza
9,388 PointsIt so does. Thanks a tonne
Lauren Moineau
9,483 PointsLauren Moineau
9,483 PointsYou're welcome! Glad I could help :)