當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。