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


Java ViewModel类代码示例

本文整理汇总了Java中android.arch.lifecycle.ViewModel的典型用法代码示例。如果您正苦于以下问题:Java ViewModel类的具体用法?Java ViewModel怎么用?Java ViewModel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ViewModel类属于android.arch.lifecycle包,在下文中一共展示了ViewModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: create

import android.arch.lifecycle.ViewModel; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public <T extends ViewModel> T create(Class<T> modelClass) {
    Provider<? extends ViewModel> creator = creators.get(modelClass);
    if (creator == null) {
        for (Map.Entry<Class<? extends ViewModel>, Provider<ViewModel>> entry : creators.entrySet()) {
            if (modelClass.isAssignableFrom(entry.getKey())) {
                creator = entry.getValue();
                break;
            }
        }
    }
    if (creator == null) {
        throw new IllegalArgumentException("unknown model class " + modelClass);
    }
    try {
        return (T) creator.get();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:NamTranDev,项目名称:CleanArchitechture,代码行数:22,代码来源:ViewModelFactory.java

示例2: create

import android.arch.lifecycle.ViewModel; //导入依赖的package包/类
@NonNull
@SuppressWarnings("unchecked")
@Override
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
    Provider<? extends ViewModel> creator = creators.get(modelClass);
    if (creator == null) {
        for (Map.Entry<Class<? extends ViewModel>, Provider<ViewModel>> entry : creators.entrySet()) {
            if (modelClass.isAssignableFrom(entry.getKey())) {
                creator = entry.getValue();
                break;
            }
        }
    }
    if (creator == null) {
        throw new IllegalArgumentException("unknown model class " + modelClass);
    }
    try {
        return (T) creator.get();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:amrro,项目名称:firestore-android-arch-components,代码行数:23,代码来源:ViewModelFactory.java

示例3: create

import android.arch.lifecycle.ViewModel; //导入依赖的package包/类
@Override
public <T extends ViewModel> T create(Class<T> modelClass) {
    Callable<? extends ViewModel> creator = creators.get(modelClass);
    if (creator == null) {
        for (Map.Entry<Class, Callable<? extends ViewModel>> entry : creators.entrySet()) {
            if (modelClass.isAssignableFrom(entry.getKey())) {
                creator = entry.getValue();
                break;
            }
        }
    }
    if (creator == null) {
        throw new IllegalArgumentException("unknown model class " + modelClass);
    }
    try {
        return (T) creator.call();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:VivekNeel,项目名称:CricKotlin,代码行数:21,代码来源:AppViewModelFactory.java

示例4: create

import android.arch.lifecycle.ViewModel; //导入依赖的package包/类
@Override
public <T extends ViewModel> T create(Class<T> modelClass) {
    if (modelClass.isAssignableFrom(EnvironmentalSensorsViewModel.class)) {
        //noinspection unchecked
        return (T) new EnvironmentalSensorsViewModel(mApplication, mEnvironmentalSensorsRepository);
    } /*else if (modelClass.isAssignableFrom(TaskDetailViewModel.class)) {
        //noinspection unchecked
        return (T) new TaskDetailViewModel(mApplication, mEnvironmentalSensorsRepository);
    } else if (modelClass.isAssignableFrom(AddEditTaskViewModel.class)) {
        //noinspection unchecked
        return (T) new AddEditTaskViewModel(mApplication, mEnvironmentalSensorsRepository);
    } else if (modelClass.isAssignableFrom(EnvironmentalSensorsViewModel.class)) {
        //noinspection unchecked
        return (T) new EnvironmentalSensorsViewModel(mApplication, mEnvironmentalSensorsRepository);
    }*/
    throw new IllegalArgumentException("Unknown ViewModel class: " + modelClass.getName());
}
 
开发者ID:igrow-systems,项目名称:igrow-android,代码行数:18,代码来源:ViewModelFactory.java

示例5: create

import android.arch.lifecycle.ViewModel; //导入依赖的package包/类
@NonNull
@SuppressWarnings("unchecked")
@Override
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
    Provider<? extends ViewModel> creator = mCreators.get(modelClass);
    if (creator == null) {
        for (Map.Entry<Class<? extends ViewModel>, Provider<ViewModel>> entry : mCreators.entrySet()) {
            if (modelClass.isAssignableFrom(entry.getKey())) {
                creator = entry.getValue();
                break;
            }
        }
    }
    if (creator == null) {
        throw new IllegalArgumentException("Unknown model class " + modelClass);
    }
    try {
        return (T) creator.get();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:leinardi,项目名称:androidthings-kuman-sm9,代码行数:23,代码来源:ViewModelFactory.java

示例6: create

import android.arch.lifecycle.ViewModel; //导入依赖的package包/类
@NonNull
@Override
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
    return (T) new TransactionsViewModel(
            findDefaultNetworkInteract,
            findDefaultWalletInteract,
            fetchTransactionsInteract,
            getDefaultWalletBalance,
            manageWalletsRouter,
            settingsRouter,
            sendRouter,
            transactionDetailRouter,
            myAddressRouter,
            myTokensRouter,
            externalBrowserRouter);
}
 
开发者ID:TrustWallet,项目名称:trust-wallet-android,代码行数:17,代码来源:TransactionsViewModelFactory.java

示例7: create

import android.arch.lifecycle.ViewModel; //导入依赖的package包/类
/**
 * creates ViewModels
 * @param modelClass (viewModelChildName).class
 * @param <T> class
 * @return ViewModel custom instance
 */
@NonNull
@Override
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
    Callable<? extends ViewModel> creator = creators.get(modelClass);
    if(creator == null){
        for(Map.Entry<Class, Callable<? extends ViewModel>> entry : creators.entrySet()){
            if(modelClass.isAssignableFrom(entry.getKey())){
                creator = entry.getValue();
                break;
            }
        }
    }

    if(creator == null){
        throw new IllegalArgumentException("Model class not found" + modelClass);
    }

    try {
        return (T) creator.call();
    }
    catch (Exception e){
        throw new RuntimeException(e);
    }
}
 
开发者ID:jakdor,项目名称:LabDayApp,代码行数:31,代码来源:ViewModelFactory.java

示例8: create

import android.arch.lifecycle.ViewModel; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public <T extends ViewModel> T create(Class<T> modelClass) {
    Provider<? extends ViewModel> creator = creators.get(modelClass);

    if (creator == null) {
        for (Map.Entry<Class<? extends ViewModel>, Provider<ViewModel>> entry : creators.entrySet()) {
            if (modelClass.isAssignableFrom(entry.getKey())) {
                creator = entry.getValue();
                break;
            }
        }
    }

    if (creator == null) {
        throw new IllegalArgumentException("Unknown model class " + modelClass);
    }

    try {
        return (T) creator.get();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:AndrejJurkin,项目名称:udacity-baking-app-mvvm-rxjava-dagger,代码行数:25,代码来源:ViewModelFactory.java

示例9: create

import android.arch.lifecycle.ViewModel; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public <T extends ViewModel> T create(Class<T> modelClass) {
    Provider<? extends ViewModel> creator = creators.get(modelClass);
    if (creator == null) {
        for (Map.Entry<Class<? extends ViewModel>, Provider<ViewModel>> entry : creators.entrySet()) {
            if (modelClass.isAssignableFrom(entry.getKey())) {
                creator = entry.getValue();
                break;
            }
        }
    }
    if (creator == null) {
        throw new IllegalArgumentException("Unknown model class " + modelClass);
    }
    try {
        return (T) creator.get();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:davideas,项目名称:AndroidBlueprints,代码行数:22,代码来源:ViewModelFactory.java

示例10: create

import android.arch.lifecycle.ViewModel; //导入依赖的package包/类
@NonNull
@Override
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
    if (modelClass.isAssignableFrom(UserListVM.class)) {
        return (T) new UserListVM(dataService);
    } else if (modelClass.isAssignableFrom(UserDetailVM.class)) {
        return (T) new UserDetailVM(dataService);
    }
    throw new IllegalArgumentException("Unknown ViewModel class: " + modelClass.getSimpleName());
}
 
开发者ID:Zeyad-37,项目名称:RxRedux,代码行数:11,代码来源:ViewModelFactory.java

示例11: create

import android.arch.lifecycle.ViewModel; //导入依赖的package包/类
@Override
public <T extends ViewModel> T create(Class<T> modelClass) {
    if (modelClass.isAssignableFrom(LoginViewModel.class)) {
        return (T) new LoginViewModel(mApplication);
    }
    throw new IllegalArgumentException("Unknown ViewModel class: " + modelClass.getName());
}
 
开发者ID:InnoFang,项目名称:Android-Code-Demos,代码行数:8,代码来源:ViewModelFactory.java

示例12: create

import android.arch.lifecycle.ViewModel; //导入依赖的package包/类
@NonNull
@Override
public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
    if (modelClass.isAssignableFrom(LogcatItemViewModel.class)) {
        return (T) new LogcatItemViewModel(application, repositoryInjection.provideItemRepo());
    } else if (modelClass.isAssignableFrom(LogcatContentViewModel.class)) {
        return (T) new LogcatContentViewModel(application, repositoryInjection.provideContentRepo());
    } else {
        throw new IllegalArgumentException("Unkonw viewmodel type: " + modelClass);
    }
}
 
开发者ID:Zane96,项目名称:Fairy,代码行数:12,代码来源:ViewModelFactory.java

示例13: create

import android.arch.lifecycle.ViewModel; //导入依赖的package包/类
@Override
public <T extends ViewModel> T create(Class<T> modelClass) {
    if (modelClass.isAssignableFrom(LoginViewModel.class)) {
        return (T) new LoginViewModel();
    }
    throw new IllegalArgumentException("Unknown ViewModel class");
}
 
开发者ID:listenzz,项目名称:RxCommand,代码行数:8,代码来源:ViewModelFactory.java

示例14: create

import android.arch.lifecycle.ViewModel; //导入依赖的package包/类
@Override
public <T extends ViewModel> T create(Class<T> modelClass) {
    if (modelClass.isAssignableFrom(ListItemCollectionViewModel.class))
        return (T) new ListItemCollectionViewModel(repository);

    else if (modelClass.isAssignableFrom(ListItemViewModel.class))
        return (T) new ListItemViewModel(repository);

    else if (modelClass.isAssignableFrom(NewListItemViewModel.class))
        return (T) new NewListItemViewModel(repository);

    else {
        throw new IllegalArgumentException("ViewModel Not Found");
    }
}
 
开发者ID:BracketCove,项目名称:RoomDemo2017,代码行数:16,代码来源:CustomViewModelFactory.java

示例15: createFor

import android.arch.lifecycle.ViewModel; //导入依赖的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


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