viewmodel

Get the same instance of ViewModel in Fragment which is defined in Activity with parameter

邮差的信 提交于 2020-06-26 12:54:11
问题 So, I am using Koin for dependency injection, Here is what I did inside a activity class ModuleDetailActivity : AppCompatActivity() { private lateinit var moduleId:String private lateinit var levelModule:Level.Module private val moduleViewModel: ModuleViewModel by viewModel { parameterOf(moduleId, levelModule) } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) ... ... moduleId = intent.getString("module_id") levelModule = intent.getParcelable("level

How to add an item to a list in a ViewModel using Razor and .NET Core?

与世无争的帅哥 提交于 2020-06-09 10:28:27
问题 So here's my situation. Let's say I have a view called TheView.cshtml. TheView.cshtml has a ViewModel called TheViewModel.cs . In TheViewModel.cs , resides a List of an object ( TheObject ) called TheObjectList . I have an editor template for TheObject called TheObject.cshtml . Using this editor template, I can simply display all of the items in the TheObjectList with @Html.EditorFor(model => model.TheObjectList) . However, now I want to dynamically add objects to this list. I have a AJAX

How to add an item to a list in a ViewModel using Razor and .NET Core?

心已入冬 提交于 2020-06-09 10:27:23
问题 So here's my situation. Let's say I have a view called TheView.cshtml. TheView.cshtml has a ViewModel called TheViewModel.cs . In TheViewModel.cs , resides a List of an object ( TheObject ) called TheObjectList . I have an editor template for TheObject called TheObject.cshtml . Using this editor template, I can simply display all of the items in the TheObjectList with @Html.EditorFor(model => model.TheObjectList) . However, now I want to dynamically add objects to this list. I have a AJAX

Use the same instance of view model in multiple fragments using dagger2

痴心易碎 提交于 2020-06-01 05:36:25
问题 I am using only dagger2 ( not dagger-android ) in my project. It's working fine to inject the ViewModel using multibinding. But there's one problem with that previously without dagger2 I was using the same instance of viewmodel used in activity in multiple fragments (using fragment-ktx method activityViewModels()), but now since dagger2 is injecting the view model it's always gives the new instance (checked with hashCode in each fragment) of the viewmodel for each fragment, that's just breaks

Room LiveData fires twice with one stale emission

蹲街弑〆低调 提交于 2020-05-29 10:28:49
问题 This issue was originally observed in a project with MVVM architecture (single activity / multiple fragments) when performing an insert/delete operation to the database and then navigating back to the home fragment. The home fragment then resubscribes to the LiveData in the home ViewModel and LiveData emits twice: One incorrect stale event corresponding to before the database operation A second correct event corresponding to after the database operation I have created a very simple example

How to get an Instance of ViewModel in activity in 2020?

帅比萌擦擦* 提交于 2020-05-27 09:27:12
问题 I am new to the mvvm pattern. I created a ViewModel for the main activity. Now I want to get an instance of the ViewModel in the main activity. Most Tutorials and answers here on Stackoverflow suggest using ViewModelProviders.of(... , but this is depreceated. So according to this question on stackoverflow: ViewModelProviders is deprecated in 1.1.0 main activity in onCreate, I do the following (and I could swear I already had it running): mainActivityViewModel = new ViewModelProvider(this).get

How to get an Instance of ViewModel in activity in 2020?

徘徊边缘 提交于 2020-05-27 09:25:26
问题 I am new to the mvvm pattern. I created a ViewModel for the main activity. Now I want to get an instance of the ViewModel in the main activity. Most Tutorials and answers here on Stackoverflow suggest using ViewModelProviders.of(... , but this is depreceated. So according to this question on stackoverflow: ViewModelProviders is deprecated in 1.1.0 main activity in onCreate, I do the following (and I could swear I already had it running): mainActivityViewModel = new ViewModelProvider(this).get

ViewModel in Kotlin: Unresolved Reference

故事扮演 提交于 2020-05-23 07:46:10
问题 I am trying to implement ViewModel in a 100% Kotlin app. Every piece of documentation I can find says I want to use this to get the ViewModel instance: ViewModelProviders.of(this).get(CustomViewModel::class.java) According to the docs, I should be able to import this with: import android.arch.lifecycle.ViewModelProviders This import is unresolved though. I am using the following in my build file: def androidArchVersion = '1.1.1' implementation "android.arch.lifecycle:viewmodel:

Why it is important to implement a ViewModelProvider.Factory for my viewModel class?

霸气de小男生 提交于 2020-05-15 03:38:06
问题 I have built a fragment that basically contains a Recyclerviewer with a custom ViewModel for my Data type using data binding and LiveData (which is a piece of code that I frequently implement) but in this time a runtime exception error has occurred! /AndroidRuntime: FATAL EXCEPTION: main Process: com.example.tdm_project, PID: 9460 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.tdm_project/com.example.tdm_project.MainActivity}: java.lang.RuntimeException: Cannot

Cannot create instance of class ViewModel while using MVVM

流过昼夜 提交于 2020-04-18 06:12:09
问题 I have created ViewModel class, and trying to create an instance of my ViewModel class using ViewModelProvider. At runtime, I'm getting this error "Cannot create an instance of class className ViewModel. Here are the required codes: MainActivity.java public class MainActivity extends AppCompatActivity { MainActivityViewModel mainActivityViewModel; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);