本文整理汇总了Java中android.arch.lifecycle.ViewModelProvider类的典型用法代码示例。如果您正苦于以下问题:Java ViewModelProvider类的具体用法?Java ViewModelProvider怎么用?Java ViewModelProvider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ViewModelProvider类属于android.arch.lifecycle包,在下文中一共展示了ViewModelProvider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initViewModels
import android.arch.lifecycle.ViewModelProvider; //导入依赖的package包/类
private void initViewModels(final String productId) {
productViewModel = ViewModelProviders.of(this, new ViewModelProvider.Factory() {
@SuppressWarnings("unchecked") @Override public <T extends ViewModel> T create(final Class<T> modelClass) {
if (modelClass.equals(RealProductViewModel.class)) {
return (T) new RealProductViewModel(productId);
} else {
return null;
}
}
}).get(RealProductViewModel.class);
productViewModel.productLiveData().observe(this, this::renderProduct);
productViewModel.progressLiveData().observe(this, progress -> {
if (progress != null) {
swipeRefreshLayoutView.setRefreshing(progress.show);
}
});
productViewModel.errorErrorCallback().observe(this.getLifecycle(), error -> {
if (error != null) {
showDefaultErrorMessage();
}
});
}
示例2: 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);
}
};
}
示例3: 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);
}
示例4: 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;
}
示例5: initViewModels
import android.arch.lifecycle.ViewModelProvider; //导入依赖的package包/类
private void initViewModels(final String collectionId) {
ProductListViewModel listViewModel = ViewModelProviders.of(this, new ViewModelProvider.Factory() {
@SuppressWarnings("unchecked")
@Override
public <T extends ViewModel> T create(final Class<T> modelClass) {
if (modelClass.equals(ProductListViewModel.class)) {
return (T) new ProductListViewModel(collectionId);
} else {
return null;
}
}
}).get(ProductListViewModel.class);
productListView.bindViewModel(listViewModel);
}
示例6: initViewModel
import android.arch.lifecycle.ViewModelProvider; //导入依赖的package包/类
@Override
public void initViewModel(ViewModelProvider.Factory factory) {
mViewModel = ViewModelProviders.of(this,factory).get(SoccerSeasonFragmentModel.class);
}
示例7: initViewModel
import android.arch.lifecycle.ViewModelProvider; //导入依赖的package包/类
@Override
public void initViewModel(ViewModelProvider.Factory factory) {
mViewModel = ViewModelProviders.of(this,factory).get(TeamFragmentModel.class);
}
示例8: bindViewModelFactory
import android.arch.lifecycle.ViewModelProvider; //导入依赖的package包/类
@Binds
abstract ViewModelProvider.Factory bindViewModelFactory(ViewModelFactory factory);
示例9: bindViewModelFactory
import android.arch.lifecycle.ViewModelProvider; //导入依赖的package包/类
@Binds
abstract ViewModelProvider.Factory bindViewModelFactory(ArchCompViewModelFactory factory);
示例10: provideViewModelFactory
import android.arch.lifecycle.ViewModelProvider; //导入依赖的package包/类
@Provides
@Singleton
ViewModelProvider.Factory provideViewModelFactory(ListItemRepository repository){
return new CustomViewModelFactory(repository);
}
示例11: bindViewModelFactory
import android.arch.lifecycle.ViewModelProvider; //导入依赖的package包/类
@Binds
abstract ViewModelProvider.Factory bindViewModelFactory(GithubViewModelFactory factory);
示例12: provideViewModelFactory
import android.arch.lifecycle.ViewModelProvider; //导入依赖的package包/类
@Provides
@Singleton
ViewModelProvider.Factory provideViewModelFactory() {
return new ViewModelProvider.NewInstanceFactory();
}
示例13: provideViewModelFactory
import android.arch.lifecycle.ViewModelProvider; //导入依赖的package包/类
@Provides
@Singleton
ViewModelProvider.Factory provideViewModelFactory(ViewModelSubComponent.Builder builder){
return new PhotoViewModelFactory(builder.build());
}
示例14: mainViewModelProvider
import android.arch.lifecycle.ViewModelProvider; //导入依赖的package包/类
@Provides
ViewModelProvider.Factory mainViewModelProvider(MainViewModel mainViewModel) {
return new ViewModelProviderFactory<>(mainViewModel);
}
示例15: provideBlogViewModel
import android.arch.lifecycle.ViewModelProvider; //导入依赖的package包/类
@Provides
ViewModelProvider.Factory provideBlogViewModel(BlogViewModel blogViewModel) {
return new ViewModelProviderFactory<>(blogViewModel);
}