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


Java ViewModelProvider.Factory方法代码示例

本文整理汇总了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);
        }
    };
}
 
开发者ID:googlesamples,项目名称:android-architecture-components,代码行数:12,代码来源:ViewModelUtil.java

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

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

示例4: 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

示例5: bindViewModelFactory

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

示例6: bindViewModelFactory

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

示例7: provideViewModelFactory

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

示例8: bindViewModelFactory

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

示例9: provideViewModelFactory

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

示例10: 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

示例11: 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

示例12: provideOpenSourceViewModel

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

示例13: provideViewModelFactory

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

示例14: bindViewModelFactory

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

示例15: LiveDataRowPresenter

import android.arch.lifecycle.ViewModelProvider; //导入方法依赖的package包/类
public LiveDataRowPresenter(ViewModelProvider.Factory factory) {
    super();
    mDataLoadedListeners = new ArrayList<>();
    viewModelFactory = factory;
}
 
开发者ID:googlesamples,项目名称:leanback-showcase,代码行数:6,代码来源:LiveDataRowPresenter.java


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