RecyclerView Adapter Dagger Dependency

preview_player
Показать описание
In this video I'm going to set up the RecyclerView for displaying the posts from the API.

I'll be displaying the posts in a RecyclerView. The RecyclerView adapter class will get provided as a dagger dependency and injected into the Fragment.

➤ Watch the dagger course free:

➤ Code for this video:
Рекомендации по теме
Комментарии
Автор

One point Mitch, when you copy some code for a class from github or any other source, just paste it in particular package, it will automatically create the class, you dont need to specificaaly create the class with same name and then paste the code in same class, it will save some of your time. Thank you. Video 2:01

mohammadmujahid
Автор

great one it is helping me a lot. thank you mitch

birukmekonnen
Автор

Hi Mitch, to inject the layout manager we would need the activity. How to refer them in MainModule since we are passing the main activity reference anywhere?

CInKannada
Автор

Thank you sir, one thing is that whenever screen is rotated, the adapter will be set again and the recycler position will jump to top. How to solve that? Also why the ViewModel is recreated again on screen rotation?

SerarEstaifan
Автор

Sir, I want to open different activities from the RecyclerView

TechknowledgeRohitgbn
Автор

Is it a good idea to field inject only the dependencies of the adapter?

alryanacain
Автор

hello, how do i provide Item Decoration as dependency as it takes it's value at runtime ?

abdomahany
Автор

Shouldn't this be static?: public class PostViewHolder extends RecyclerView.ViewHolder

David-yzmb
Автор

7:37 Seems that VerticalSpacingItemDecoration didn't show up... unless you didn't make it just a blank spaceholder

kirill
Автор

hey mitch i tend to follow the pattern wherein i pass the list in the constructor of the adapter, since i follow it, injecting the adapter is cumbersome, but i saw you had an explicit method to set the posts so my practice isn't good or what ?

theonlyarjun
Автор

if your app crash when you debug I used getViewmodelStore instead of this in fragment to " ViewModelProvider(viewModelStore, "

oguzhancetin
Автор

Thank you, but how make onclicklistener in better way with dagger and MVVM and fragment?

maksimzobin
Автор

I forget to call initRecyclerView(), so I spend my time trying to figure out what was my mistake.

franciscollaryora
Автор

For those of you looking for LinearLayoutmanager and VerticalSpacingItemDecoration injection:
Main Module: @MainScope
@Provides
static LinearLayoutManager mainActivity){
return new LinearLayoutManager(mainActivity, RecyclerView.VERTICAL, false);
}
@MainScope
@Provides
static VerticalSpacingItemDecoration
return new
}
PostFragment:

@Inject
LinearLayoutManager linearLayoutManager;
@Inject
VerticalSpacingItemDecoration
Please reply if you have a better solution. :)

AkshanshGusain
Автор

I don't love copy nd pasting :'(

grasstogains