MVVM | Android MVVM框架 | Android library
kandi X-RAY | MVVM Summary
kandi X-RAY | MVVM Summary
Android MVVM框架
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Check the validity of a bitmap .
- Upload a file .
- Completes the given edit .
- Read a line from the buffer .
- Get data from disk cache .
- Checks to see if the current device is FastMobile
- Computes the MD5 of a file .
- Read the text into a List
- Shows the temp view .
- Called when a navigation item is selected .
MVVM Key Features
MVVM Examples and Code Snippets
Community Discussions
Trending Discussions on MVVM
QUESTION
I'm new to Android development and I'm currently building my first real app. I'm trying to implement a MVVM architecture and because of that I'm having a viewModel for each fragment and each viewModel has a viewModelFactory. At least, this is how I understood it has to be.
I use the boilerplate code everyone seems to use for the factory:
...ANSWER
Answered 2022-Feb-25 at 16:53It seems like you are either directly or indirectly (through some other library) depending on Lifecycle 2.5.0-alpha01
.
As per this issue:
You need to temporarily add following to your
build.gradle
:
QUESTION
As a developer one needs to adapt to change, I read somewhere it says:
If you don’t choose the right architecture for your Android project, you will have a hard time maintaining it as your codebase grows and your team expands.
I wanted to implement Clean Architecture
with MVVM
My app data flow will look like this:
Model class
...ANSWER
Answered 2022-Mar-14 at 09:37Try to remove additional lists of items in the fetchFirestoreData()
and showMenu()
(for item R.id.option_delete
) methods of the HomeFragment
fragment and see if it works:
QUESTION
This is my first time using a javascript framework, I would like to implement MVVM in my EXT JS application and the data is coming from my WEB API (ASP.NET FRAMEWORK).
My problem is that, I don't seem to understand how to fully use viewModel which looks up to my store. I successfully bound my ViewModel in my grid but now I don't know how to update the selected record using a form (modal) and sync my store (send update request through API)
I have a feeling that I'm doing it the wrong way. I don't know how to do this in fiddle so I'll just paste my code here.
- Genre.js [Model]
ANSWER
Answered 2022-Mar-07 at 23:26To do store.sync()
you need to set values on the record
first.
Example is without ViewModel: https://fiddle.sencha.com/#fiddle/3isg&view/editor
QUESTION
I'm building a WPF/MVVM application that displays some lists below each other. My MainViewModel contains in addition to the lists a textbox, whose text content I want to use as a filter for my lists. However, these lists are not in the MainViewModel, but in sub-controls (UserControl2_*).
If the filter property is in the same ViewModel as the ICollectionView, then filtering works (see CollectionViewFilter in ViewModel2.cs), but I don't understand how to apply a filter to multiple Sub-ViewModels.
Is there an MVVM compliant method to pass the filter through to the sub-controls? Or do I need to pass the collections up so that I can access them from the ViewModel, where the filter property is also set?
If there is any more code you want me to upload or adapt, let me know and I will edit my question.
...ANSWER
Answered 2022-Jan-04 at 15:01You'll have to link the CollectionView
s and the filter method at some point, so your UserControl needs to allow that. I can think of three ways to do it:
Have your UserControl handle its own
CollectionView
, and add a method to configure your filter (take aPredicate as parameter and set that to the Filter property).
Have your UserControl expose a method which returns a
CollectionView
for your list, and do everything in the MainWindow. Less pretty, but still probably alright, and avoids creating unnecessary stuff when you just want to display a list without any option.The most "MVVM" way to do it would be to add a
DependencyProperty
to your UserControl, with aPropertyChangedCallback
that updates the filtering of objects. Then you can bind to a property of your mainwindow's viewmodel, and update that property based on your text field. Here's an example from some code i have :
QUESTION
Im new in xamarin, Im trying to make a Button that opens a scanner form that scans qr/barcode that is MVVM method. Im trying to get the result and display it into a label. this is my best guest but it doesn't work, hope someone can help.
...ANSWER
Answered 2021-Dec-22 at 09:51You can use the code-behind the view for the actions. And use the VM for other properties
XAML:
QUESTION
I have a problem with making a game using Xamarin.Forms and MVVM.
In the game there's a submarine which is controlled by the user and there are mines falling down so the user has to avoid these mines. The mines are generated in runtime using 2 timers, so I represent these with a CollectionView in XAML.
I already made this game using WPF (and also using WinForms) and in that case I used Canvas for the game area (ItemsControl for the mines) and the bindings works well. Now (using Xamarin.Forms) I tried implementing the game area with AbsoluteLayout and with RelativeLayout, but always received eg. the following output (RelativeLayout):
[0:] Binding: '160' cannot be converted to type 'Xamarin.Forms.Constraint'
The current XAML code:
...ANSWER
Answered 2021-Dec-30 at 00:57From the error:
[0:] Binding: '160' cannot be converted to type 'Xamarin.Forms.Constraint'
You can see that it can't convert the integer to the type Constraint
that is expected by the binding expression.
When you do this:
QUESTION
I'm trying to learn MVVM to make my app's architecture more clean. But I'm having a hard time grasping how to create a "Domain" layer for my app.
Currently this is how the structure of my project is looking:
My View
is the activity. My ViewModel
has a public method that the activity can call. Once the method in the ViewModel is called, it calls a method in my Repository
class which performs a network call, which then returns the data back to the ViewModel. I then update the LiveData
in the ViewModel so the Activity's UI is updated.
This is where I'm confused on how to add a Domain
layer to the structure. I've read a lot of Stackoverflow answers and blogs about the Domain layer and they mostly all tell you to remove all the business logic from the ViewModel
and make a pure Java/Kotlin class.
So instead of
View --> ViewModel --> Repository
I would be communicating from the ViewModel
to the Domain
class and the Domain
class would communicate with the Repository
?
View --> ViewModel --> Domain --> Repository
I'm using RxJava
to make the call from my ViewModel
to the Repository
class.
ANSWER
Answered 2021-Dec-15 at 01:50I had a hard time while trying to figure out the domain layer. The most common example of it is the use case.
Your viewmodel won't communicate directly to the repository. As you said, you need viewmodel 》domain 》repository.
You may think of a usecase as a abstraction for every repository method.
Let's say you have a Movies Repository where you call a method for a movie list, another method for movie details and a third method for related movies.
You'll have a usecase for every single method.
What's the purpose of it?
Let's say you have a DetailActivity that communicate with a Detail Viewmodel. Your viewmodel doesn't need to know all the repository (what's the purpose of calling a movie list method on you Detail screen?). So, all your DetailViewModel will know is "Detail Usecase " (that calls the Detail method in repository).
Google has updated the architecture documentation few hours ago, take a look! https://android-developers.googleblog.com/2021/12/rebuilding-our-guide-to-app-architecture.html?m=1&s=09
PS: Usecase is not a special android class, you do not need to inherent any behavior (as fragment, activity, viewmodel...) it's a normal class that will receive the repository as parameter.
You'll have something like:
Viewmodel:
QUESTION
Context
I started working on a new project and I've decided to move from RxJava to Kotlin Coroutines. I'm using an MVVM clean architecture, meaning that my ViewModels
communicate to UseCases
classes, and these UseCases
classes use one or many Repositories
to fetch data from network.
Let me give you an example. Let's say we have a screen that is supposed to show the user profile information. So we have the UserProfileViewModel
:
ANSWER
Answered 2021-Dec-06 at 14:53The most obvious problem I see here is that you're using Flow
for single values instead of suspend
functions.
Coroutines makes the single-value use case much simpler by using suspend functions that return plain values or throw exceptions. You can of course also make them return Result
-like classes to encapsulate errors instead of actually using exceptions, but the important part is that with suspend
functions you are exposing a seemingly synchronous (thus convenient) API while still benefitting from asynchronous runtime.
In the provided examples you're not subscribing for updates anywhere, all flows actually just give a single element and complete, so there is no real reason to use flows and it complicates the code. It also makes it harder to read for people used to coroutines because it looks like multiple values are coming, and potentially collect
being infinite, but it's not the case.
Each time you write flow { emit(x) }
it should just be x
.
Following the above, you're sometimes using flatMapMerge
and in the lambda you create flows with a single element. Unless you're looking for parallelization of the computation, you should simply go for .map { ... }
instead. So replace this:
QUESTION
Is it a good practice to use provider in place of setstate talking for MVVM architecture and in general also? Does provider rebuilds the whole app widget tree like if i trigger it in second page than will 1st page also be rebuilt, if so then how can we use it more effectevly?
...ANSWER
Answered 2021-Nov-21 at 13:05Provider state management offer Consumer. That Consumer has a build function itself. So you can use consumer in which widget you want to rebuild. You don't need to rebuild the whole widget tree. Consumer will listen your provider method and it will rebuild a specific widget where you want to change. Thanks
QUESTION
I'm working on a trading app. I need to list the user stocks and their value (profit or loss) among with the total value of the portfolio.
For the holdings list, in an MVP architecture I would create a presenter for each list item but for this app I decided to use MVVM (Compose, ViewModels and Hilt ). My first idea was to create a different ViewModel for each list item. I'm using hiltViewModel()
in the composable method signature to create instances of my ViewModel, however this gives me always the same instance and this is not what I want. When using MVVM architecture, is what I'm trying to do the correct way or I should use a single ViewModel? Are you aware about any project I could have a look at? The image below is a super simplification of my actual screen, each cell is complex and that's why I wanted to use a different ViewModel for each cell. Any suggestion is very welcome.
ANSWER
Answered 2021-Oct-28 at 15:38Unfortunately, HiltViewModelFactory
is not a KeyedFactory
. So as of now it does not support same viewModel with multiple instances.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install MVVM
You can use MVVM like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the MVVM component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page