How can i create a viewModel with a generic type? Let me show you an example:
ViewModel
public class MyViewModel<T> extends ViewModel
{
private Repository<T> repository;
...
@Override
public LiveData<Model<T>> getModel()
{
return repository.getModel();
}
}
Fragment
private MyViewModel<T> viewModel;
...
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState)
{
super.onActivityCreated(savedInstanceState);
// this is where i need my viewModel with the generic type
viewModel = ViewModelProviders.of(this).get(MyViewModel.class);
}
As you can see, i am unable to get the sepecified viewModel i initialized as a variable in my fragment Maybe someone can lead me in the right direction, thanks.