当前位置: 首页>>代码示例>>Java>>正文


Java ViewModelProvider类代码示例

本文整理汇总了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();
    }
  });
}
 
开发者ID:Shopify,项目名称:mobile-buy-sdk-android,代码行数:23,代码来源:ProductDetailsActivity.java

示例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);
        }
    };
}
 
开发者ID:googlesamples,项目名称:android-architecture-components,代码行数:12,代码来源:ViewModelUtil.java

示例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);
}
 
开发者ID:graviton57,项目名称:NewAndroidArchitecture,代码行数:8,代码来源:MainActivity.java

示例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;
}
 
开发者ID:googlesamples,项目名称:leanback-showcase,代码行数:10,代码来源:PresenterModule.java

示例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);
}
 
开发者ID:Shopify,项目名称:mobile-buy-sdk-android,代码行数:15,代码来源:ProductListActivity.java

示例6: initViewModel

import android.arch.lifecycle.ViewModelProvider; //导入依赖的package包/类
@Override
public void initViewModel(ViewModelProvider.Factory factory) {
    mViewModel = ViewModelProviders.of(this,factory).get(SoccerSeasonFragmentModel.class);
}
 
开发者ID:NamTranDev,项目名称:CleanArchitechture,代码行数:5,代码来源:SoccerSeasonMvvmFragment.java

示例7: initViewModel

import android.arch.lifecycle.ViewModelProvider; //导入依赖的package包/类
@Override
public void initViewModel(ViewModelProvider.Factory factory) {
    mViewModel = ViewModelProviders.of(this,factory).get(TeamFragmentModel.class);
}
 
开发者ID:NamTranDev,项目名称:CleanArchitechture,代码行数:5,代码来源:TeamMvvmFragment.java

示例8: bindViewModelFactory

import android.arch.lifecycle.ViewModelProvider; //导入依赖的package包/类
@Binds
abstract ViewModelProvider.Factory bindViewModelFactory(ViewModelFactory factory);
 
开发者ID:NamTranDev,项目名称:CleanArchitechture,代码行数:3,代码来源:ViewModelModule.java

示例9: bindViewModelFactory

import android.arch.lifecycle.ViewModelProvider; //导入依赖的package包/类
@Binds
abstract ViewModelProvider.Factory bindViewModelFactory(ArchCompViewModelFactory factory);
 
开发者ID:hbmartin,项目名称:firebase-chat-android-architecture-components,代码行数:3,代码来源:ViewModelModule.java

示例10: provideViewModelFactory

import android.arch.lifecycle.ViewModelProvider; //导入依赖的package包/类
@Provides
@Singleton
ViewModelProvider.Factory provideViewModelFactory(ListItemRepository repository){
    return new CustomViewModelFactory(repository);
}
 
开发者ID:BracketCove,项目名称:RoomDemo2017,代码行数:6,代码来源:RoomModule.java

示例11: bindViewModelFactory

import android.arch.lifecycle.ViewModelProvider; //导入依赖的package包/类
@Binds
abstract ViewModelProvider.Factory bindViewModelFactory(GithubViewModelFactory factory);
 
开发者ID:googlesamples,项目名称:android-architecture-components,代码行数:3,代码来源:ViewModelModule.java

示例12: provideViewModelFactory

import android.arch.lifecycle.ViewModelProvider; //导入依赖的package包/类
@Provides
@Singleton
ViewModelProvider.Factory provideViewModelFactory() {
    return new ViewModelProvider.NewInstanceFactory();
}
 
开发者ID:amitkma,项目名称:android-architecture-boilerplate,代码行数:6,代码来源:ApplicationModule.java

示例13: provideViewModelFactory

import android.arch.lifecycle.ViewModelProvider; //导入依赖的package包/类
@Provides
@Singleton
ViewModelProvider.Factory provideViewModelFactory(ViewModelSubComponent.Builder builder){
    return new PhotoViewModelFactory(builder.build());
}
 
开发者ID:vmosconecds,项目名称:PhotoExample,代码行数:6,代码来源:AppModule.java

示例14: mainViewModelProvider

import android.arch.lifecycle.ViewModelProvider; //导入依赖的package包/类
@Provides
ViewModelProvider.Factory mainViewModelProvider(MainViewModel mainViewModel) {
    return new ViewModelProviderFactory<>(mainViewModel);
}
 
开发者ID:MindorksOpenSource,项目名称:android-mvvm-architecture,代码行数:5,代码来源:MainActivityModule.java

示例15: provideBlogViewModel

import android.arch.lifecycle.ViewModelProvider; //导入依赖的package包/类
@Provides
ViewModelProvider.Factory provideBlogViewModel(BlogViewModel blogViewModel) {
    return new ViewModelProviderFactory<>(blogViewModel);
}
 
开发者ID:MindorksOpenSource,项目名称:android-mvvm-architecture,代码行数:5,代码来源:BlogFragmentModule.java


注:本文中的android.arch.lifecycle.ViewModelProvider类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。