I have seen a number of references to ViewModel.Factory
but every example I have come across has references to dependency injection. Based on this question: Why a viewmodel factory is needed in Android? it would seem that this is required when your constructor has parameters. Does this also apply to projects that aren't using dependency injection frameworks like Dagger
?
Here is what I am trying to do:
public CatalogVerticalListViewModel(@NonNull Application application, RecyclerView.Adapter adapter) {
super(application);
final CatalogAdapter catalogAdapter = (CatalogAdapter) adapter;
CatalogManager cm = new CatalogManager(Constants.BASE_URL);
pageData = cm.getCatalog();
}
I need/want to pass my adapter into the ViewModel
and I am wondering if I need to create a custom factory for this. If so, how would that look?