我有以下代码:
public class ProjectFragment extends LifecycleFragment implements Injectable {
@Inject
ViewModelProvider.Factory viewModelFactory;
private ProjectViewModel viewModel
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
viewModel = ViewModelProviders.of(this, viewModelFactory)
.get(ProjectViewModel.class);
// …
}
来自:http://jsfiddle.net/jh4wztab/1/
的源代码我想直接使用@Inject ProjectViewModel。我怎样才能做到这一点? 我没有找到任何例子。