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 trialsai 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
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 :)