Questions tagged [viewmodel]
A view model or viewpoints framework is a framework which defines a coherent set of views to be used in the construction of an architecture. A view is a representation of a whole system from the perspective of a related set of concerns.
4,516
questions
1
vote
1
answer
10
views
Safe-args: Passing an object from an imported package. Possible?
I'm trying to pass a Track object from the GPX Parser package that I've imported.
This is my navigation xml:
<argument
android:name="track_to_pass"
app:argType="io....
-1
votes
1
answer
46
views
WPF - MVVM - How does the ViewModel set its Properties?
My question is, where exactly do I call my "GetBookInformation()" Method and assign its return value to the ViewModel Property "Books"?
Do I do all of this inside of the ViewModel ...
0
votes
1
answer
46
views
Abstract room database implementation not found dagger hilt
I am new to Android dev and need to build my first project for university.
The university was using the old XML version with Java, but I wanted to learn Compose so I learnt Kotlin.
Now after getting ...
0
votes
1
answer
35
views
Using one activity for multiple Fragments, how many ViewModels should I use
I've got an app that only uses one ViewModel to handle GroceryItem.kt items from local Room database. I'm planning on adding multiple fragments using bottom navigation with NavGraph and want to ...
-2
votes
0
answers
33
views
Sharing same API between 2 activities
In very old java codebase, how we can share API between 2 Activity?
Also in old codebase we are not using RxJava, ViewModel,LiveData,Room.
For API Calling we have used Retrofit. After API Response ...
0
votes
1
answer
24
views
ASP.NET MVC passing a value from a variable on a controller to a view
I´m trying to pass a value from a variable var profit = income - expenses that is inside of an ActionResult on controller.
Does anyone know how is it possible to call this variable on a view? (With a ...
0
votes
3
answers
65
views
Do I have to use an ObservableObject in SwiftUI?
I would like to use a struct instead of a class as a state for my View, and as you may know, ObservableObject is a protocol only classes can conform to.
Do I have to wrap my struct in a ViewModel or ...
0
votes
0
answers
26
views
Response Handle
I am pulling data database,
My response class
sealed class Response<out T>{
object Loading: Response<Nothing>()
data class Success<out T>(val data: T): Response<T>()
...
1
vote
0
answers
61
views
Buttons that start invisible (Binding to false property) don't fire command when made visible later
In my MainPage.xaml I have a CollectionView in a frame and three image buttons in a frame
I'd like the first button to be visible and when I tap it it makes the other two buttons visible and tap again ...
0
votes
0
answers
13
views
Is it possible to use view-model if a class extends old android activity
What currently I am able to do
In a class that extends AppCompactActivity we can use view-model - Reference
What I am trying to find out
Is there a way to use a view-model if a class extends Activity....
0
votes
0
answers
16
views
Service messenger code should be on activity or in viewmodel? MVVM android
i have a bound service who recieves data from a messenger my question is if this code (for example)
val msg: Message = Message.obtain(null, 1, 0, 0,peso)
try {
...
0
votes
1
answer
22
views
Jetpack Compose - Search bar won't allow me to search and the cursor will not show up
I have a custom search bar will not allow me to place a cursor and type text into it. Before adding the viewmodel and state, I was able to have the TextField work and allow typing text into it.
I've ...
1
vote
1
answer
55
views
How can I use shared view model in jetpack compose for one textfield?
I have one textfield for user phone number, and I want to use this phone number for both register users to Firestore and using it for mobile authentication, so I have two ViewModel and I want to use ...
1
vote
1
answer
101
views
Swiftui: List not displaying loaded data from viewModel
Hope you're well! I have an issue where updates to an array in my view model aren't getting picked up until I exit and re-open the app.
Background: My App loads a view from a CSV file hosted on my ...
0
votes
1
answer
17
views
Flow block is not executing, call generated from ViewModel
Can't understand why the flow block doesn't execute and control returns back to ViewModel.
ViewModel code
fun getFilesFromServer() {
viewModelScope.launch(Dispatchers.IO) {
...
0
votes
1
answer
26
views
How can I fix this error for view Model? (Occurs when running the program on the emulator)
Error running program on emulator:
2022-06-16 15:38:04.724 12519-12555/com.example.mvvm E/AwareLog:
AtomicFileUtils: readFileLines file not exist:
android.util.AtomicFile@5abc123
2022-06-16 15:38:04....
0
votes
0
answers
18
views
MVVM Best Practices: communication hildren view models
I wanted to implement combobox select event, which is sent from Children1 to Children2.
I implemented communication in the following way.
Is this a good way?
If there is a better way, please reply.
//...
0
votes
1
answer
82
views
WPF - MVVM big Models or big View Models
I have spent some time searching about MVVM in WPF. I'm familiar with C# and WPF. I also understand MVVM and its benefits. I don't really know how to go about my view models and models as the multiple ...
0
votes
0
answers
13
views
How to share viewModel between dialog fragments
I found something interesting in trackr that use same view-model for three dialog-fragments:
private val viewModel: TaskEditViewModel by hiltNavGraphViewModels(R.id.nav_task_edit_graph)
I wonder how ...
0
votes
1
answer
31
views
Xamarin Forms, a ViewModel gets data to the property, but doesn't show in the View
I have a 2 Views and 2 ViewModels, the first one has a button for each category that sends a value to the ViewModel Command, which push the second View/ViewModel with the data sent.
That data is ...
0
votes
0
answers
24
views
Setting value into SavedStateHandle not working
I have 2 values which I want to store in a SavedStateHandle.
I have a view model which takes a SavedStateHandle as Parameter:
@HiltViewModel
class ArtistViewModel @Inject constructor(
private val ...
2
votes
1
answer
61
views
How to until wait 2 parallel retrofit calls both finish?
I want to call 2 retrofit services in parallel and then do an action only when both of them finished, but I don't seem to figuer it out how.
I have a viewModel where I have defined my services:
var ...
0
votes
0
answers
15
views
How to manage edit text inside recyclerview while configuration change?
i m working on a app where i have to add dynamic edittext on button click for that i used recyclerview and add editext on button click like
val noteItem = NoteData(text = "default note text",...
0
votes
1
answer
31
views
getIntExtra in ViewModel android
I have been trying to convert this small project to MVVM, where i switch the json file based on the previous activity, but i cannot use this intent.getIntExtra in ViewModel. how do i achieve that, the ...
1
vote
0
answers
46
views
java.io.NotSerializableException: androidx.lifecycle.ViewModelLazy
Putting my app on the background or changing into another app, makes my app crash in the background with the error
java.lang.RuntimeException: Parcelable encountered IOException writing serializable ...
0
votes
1
answer
28
views
Unable to insert entity using room
I am new to android Room and trying to insert some one-to-many relationships into my database. But I am facing some issues that I have not managed to fix sofar.
Here is my data constellation:
Entity:
@...
0
votes
1
answer
20
views
Where is PLANT_ID_SAVED_STATE_KEY set in sunflower app example?
I am using the sunflow app example (https://github.com/android/sunflower) as a basis to learn Hilt, Room and many other nice concepts of android coding.
In the PlantDetailViewModel class there is ...
0
votes
0
answers
14
views
Recyclerview position in MVVM
When im implementing ViewModel in RecyclerView in <data> tag, like...
<data>
<variable name="model" type=".MyViewModel" />
</data>
<Button
...
0
votes
1
answer
24
views
WPF component content not updating after view model change
I have the following view model:
public class ViewModel : ObservableObject
{
public string Watermark { get; set; } = "Loading...";
}
where ObservableObject is from Microsoft.Toolkit....
0
votes
1
answer
87
views
Non-overridable members may not be used in setup / verification expressions
I'm trying to do some unittesting on a method that is in a FreshMVVM view model (so no interface).
I want to parse two properties with values as well.
I think I found the way to parse the properties. ...
0
votes
1
answer
67
views
Best practice for hiltviewmodel in compose
So i have a few questions about using hiltviewmodels, states and remember in compose.
For some context, i have a ViewPager set up
HorizontalPager(
count = 4,
modifier = ...
0
votes
0
answers
33
views
Verification failed: call 1 of 1: InfoRepository(infoRepository#29).insert(eq([infoObj]), eq([]), any())) was not called
// Tests Function In Test Class
@Test
fun checkInsertInfo() {
val infos: MutableList<Info> = mutableListOf()
val info = Info()
info.infoNumber = "1"
infos.add(info)
...
0
votes
2
answers
191
views
Cannot create an instance of class view model - Kotlin
I'm currently working on a project to practice dependency injection with Dagger-Hilt, however I can't get my ViewModel to instantiate, I've already looked at some other questions on the same topic, ...
0
votes
0
answers
15
views
RecyclerView not populating from Room DB ViewModel
I'm trying to show data from db to RecyclerView from ViewModel, but unable to see the list on home screen. I'm new to MVVM model.
I've implemented POJO class for product and implemented Room DB using ...
1
vote
0
answers
59
views
Flutter MVVM Passing view model as parameter between screens instead of passing models or variables
I was just looking through one of my staffs code and I noticed he passed the actual view model to a new screen instead of just passing a variable parameter like below:
final LoginScreenViewModel model;...
0
votes
0
answers
51
views
Error with injecting view model using Dagger 2
I just started learning Dagger 2 and trying to make subcomponent for subcomponent. I faced error and can't find where it comes from. Below I will write my dagger structure.
AppComponent
-AppModule
-...
0
votes
2
answers
34
views
How to add CountDownTimer to a ViewModel Kotlin?
I am trying to add a CountDownTimer to a ViewModel to be able to rotate a screen without losing data in this case a countt timer. In my code, I don't know how to return countdowntimer value from a ...
0
votes
0
answers
34
views
Collecting Flow<List> and displaying it in Compose (Kotlin)
Hello guys I have list of movies that I call from MovieApi.
In movieRepo I did this:
override suspend fun getPopularMovies() : Flow<List<Movie>>{
val popularMovies : Flow<List&...
0
votes
1
answer
38
views
MotionLayout seems to lose some constraints during animation
I have a problem:
I have a TextView whose content is constantly changing via LiveData. This looks all right when the animation isn't executing, but when the MotionLayout starts executing, my text gets ...
1
vote
1
answer
124
views
Shared view model in android compose project while using Hilt for dependency injection?
Anyone has any clue how to retain a shared view model object across different composables?
I'm using hilt and injecting viewmodel instance using hilt in composable.
Basically there are 3 screens which ...
0
votes
0
answers
45
views
Testing viewModel with coroutines live data, I am getting only loading state, other states success or fail not triggering
This is viewmodel class.
@HiltViewModel
class MainViewModel @Inject constructor(private val mainRepository: MainRepos) : ViewModel() {
fun get(query:String) = liveData(Dispatchers.IO) {
emit(...
1
vote
1
answer
69
views
Xamarin: Bind picker selected item with FreshMvvM ViewModel
I'm creating a form where a product status needs to be selected with a dropdown menu.
I've created a picker for this. The data is loaded from a list in my ViewModel, but it doesn't get sent back.
I've ...
0
votes
1
answer
40
views
Injecting a single dependency to a view model
I want the LoginViewModel to have a single dependency of LoginViewModelService.
LoginViewModelService in itself cannot have an implementation.
Its methods will be implemented by both the ...
1
vote
0
answers
44
views
Usecase inside a custom view
First of all, sorry for my english, this is google translator.
I am learning mvvm, maybe I have some misconception but I think I can understand it well.
My goal is to load an image in an imageview, ...
0
votes
0
answers
17
views
.NET Core MVC View generated from ViewModel don't detect Key property without DBContext
I have observe some odd behaviors of net core mvc. (VS2019 16.11.13)
Assume I have a ViewModel class:
public class Employee
{
[Key]
public string EmployeeNo
{
get;
set;
...
0
votes
1
answer
103
views
Store data and "Cannot create an instance of class ViewModel" - Hilt - Room - JetpackCompose
I try to store some days from ScheduleScreen screen. Lib uses in theme topic.
While I was doing this, I had two questions:
why i got this error
Cannot create an instance of class com.example.ic....
2
votes
1
answer
134
views
How to access the Login state from everywhere? Jetpack Compose + MVVM
I'm building my app in Jetpack Compose and use one ViewModel for every feature/screen.
Now I need to access the login state from everywhere inside the app, I also have a coin system where I need ...
0
votes
3
answers
54
views
Bind viewmodel property to property in custom view
I created a custom view (NavProgressbar) which has a step property.
private static readonly BindableProperty ProgressStepProperty = BindableProperty.Create(
nameof(ProgressStep), typeof(...
0
votes
1
answer
95
views
Reactive UI / Blazor: Why is a View that inherits from ReactiveInjectableComponentBase<T> rendered twice?
When I inherit a View from ReactiveInjectableComponentBase<T> the body of the View will be "rendered" twice. I noticed this because a @foreach loop was executed twice on activation of ...
0
votes
0
answers
46
views
Save states between screens with BottomNavBar - Jetpac Compose
As the title suggests - I want to save the states of screen elements. That is, I want to switch something on screen A, go to screen B, return to screen A and have all the changes in screen A saved. I ...