本文整理汇总了Java中android.arch.lifecycle.ViewModelProvider.Factory方法的典型用法代码示例。如果您正苦于以下问题:Java ViewModelProvider.Factory方法的具体用法?Java ViewModelProvider.Factory怎么用?Java ViewModelProvider.Factory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.arch.lifecycle.ViewModelProvider
的用法示例。
在下文中一共展示了ViewModelProvider.Factory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createFor
import android.arch.lifecycle.ViewModelProvider; //导入方法依赖的package包/类
public static <T extends ViewModel> ViewModelProvider.Factory createFor(T model) {
return new ViewModelProvider.Factory() {
@Override
public <T extends ViewModel> T create(Class<T> modelClass) {
if (modelClass.isAssignableFrom(model.getClass())) {
return (T) model;
}
throw new IllegalArgumentException("unexpected model class " + modelClass);
}
};
}
示例2: getViewModel
import android.arch.lifecycle.ViewModelProvider; //导入方法依赖的package包/类
@NonNull
private CountriesViewModel getViewModel() {
CountriesService service = ApiClient.getCountriesService();
CountryDao moviesDao = CountriesDatabase.getInstance(this).countryDao();
ViewModelProvider.Factory factory = new CountriesViewModelProviderFactory(service, moviesDao);
return ViewModelProviders.of(this, factory).get(CountriesViewModel.class);
}
示例3: provideLiveDataRowPresenter
import android.arch.lifecycle.ViewModelProvider; //导入方法依赖的package包/类
@PerFragment
@Provides
public LiveDataRowPresenter provideLiveDataRowPresenter(ViewModelProvider.Factory factory,
DataLoadedListener activity) {
LiveDataRowPresenter rowPresenter = new LiveDataRowPresenter(factory);
rowPresenter.registerDataLoadedListener(activity);
return rowPresenter;
}
示例4: initViewModel
import android.arch.lifecycle.ViewModelProvider; //导入方法依赖的package包/类
@Override
public void initViewModel(ViewModelProvider.Factory factory) {
mViewModel = ViewModelProviders.of(this,factory).get(SoccerSeasonFragmentModel.class);
}
示例5: bindViewModelFactory
import android.arch.lifecycle.ViewModelProvider; //导入方法依赖的package包/类
@Binds
abstract ViewModelProvider.Factory bindViewModelFactory(ViewModelFactory factory);
示例6: bindViewModelFactory
import android.arch.lifecycle.ViewModelProvider; //导入方法依赖的package包/类
@Binds
abstract ViewModelProvider.Factory bindViewModelFactory(ArchCompViewModelFactory factory);
示例7: provideViewModelFactory
import android.arch.lifecycle.ViewModelProvider; //导入方法依赖的package包/类
@Provides
@Singleton
ViewModelProvider.Factory provideViewModelFactory(ListItemRepository repository){
return new CustomViewModelFactory(repository);
}
示例8: bindViewModelFactory
import android.arch.lifecycle.ViewModelProvider; //导入方法依赖的package包/类
@Binds
abstract ViewModelProvider.Factory bindViewModelFactory(GithubViewModelFactory factory);
示例9: provideViewModelFactory
import android.arch.lifecycle.ViewModelProvider; //导入方法依赖的package包/类
@Provides
@Singleton
ViewModelProvider.Factory provideViewModelFactory() {
return new ViewModelProvider.NewInstanceFactory();
}
示例10: mainViewModelProvider
import android.arch.lifecycle.ViewModelProvider; //导入方法依赖的package包/类
@Provides
ViewModelProvider.Factory mainViewModelProvider(MainViewModel mainViewModel) {
return new ViewModelProviderFactory<>(mainViewModel);
}
示例11: provideBlogViewModel
import android.arch.lifecycle.ViewModelProvider; //导入方法依赖的package包/类
@Provides
ViewModelProvider.Factory provideBlogViewModel(BlogViewModel blogViewModel) {
return new ViewModelProviderFactory<>(blogViewModel);
}
示例12: provideOpenSourceViewModel
import android.arch.lifecycle.ViewModelProvider; //导入方法依赖的package包/类
@Provides
ViewModelProvider.Factory provideOpenSourceViewModel(OpenSourceViewModel openSourceViewModel) {
return new ViewModelProviderFactory<>(openSourceViewModel);
}
示例13: provideViewModelFactory
import android.arch.lifecycle.ViewModelProvider; //导入方法依赖的package包/类
@Singleton
@Provides
ViewModelProvider.Factory provideViewModelFactory(ViewModelSubComponent.Builder viewModelBuilder){
return new ViewModelFactory(viewModelBuilder.build());
}
示例14: bindViewModelFactory
import android.arch.lifecycle.ViewModelProvider; //导入方法依赖的package包/类
@Binds
@Singleton
abstract ViewModelProvider.Factory bindViewModelFactory(ViewModelFactory factory);
示例15: LiveDataRowPresenter
import android.arch.lifecycle.ViewModelProvider; //导入方法依赖的package包/类
public LiveDataRowPresenter(ViewModelProvider.Factory factory) {
super();
mDataLoadedListeners = new ArrayList<>();
viewModelFactory = factory;
}