本文整理匯總了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);
}
};
}