本文整理汇总了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);
}
}
示例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);
}
}
示例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);
}
}
示例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());
}
示例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);
}
}
示例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);
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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());
}
示例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());
}
示例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);
}
}
示例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");
}
示例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");
}
}
示例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);
}
};
}