Reputation: 42824
I am Exploring Dagger for the dependency injection in Android .
What I discovered:
SharedPreferences
services
Retrofit
InstancesQuestions:
What I am trying to find:
ImageView
, Button
etc?Upvotes: 1
Views: 310
Reputation: 21417
Can we inject view objects like
ImageView
,Button
etc?
Since you mentioned Roboguice as a point of reference in your question, I am taking this question to mean can you do something the following in Dagger 2:
@InjectView(R.id.my_view) View view;
The answer to this question is 'no'. In other words, Dagger 2 includes no special syntax for injecting Views that would otherwise be obtained through findViewById(int id)
.
If not possible what is the best alternative (I am aware Roboguice is deprecated)?
Butterknife is a good companion to Dagger 2 in that it uses the same approach of code generation to allow you to inject views.
Alternatively, the Data Binding Library will allow you to do this.
Upvotes: 1