Android MVVM Kotlin Tutorial - LiveData + ViewModel (Android Architecture Components)

Reso Coder · 218K views · 2018 · 35:53

Open on YouTube

Software architecture & designSoftware practice, open source & careerstutorialdated

Why Stack Overflow recommends it

Stack Overflow users cite it as the tutorial they followed when setting up MVVM with LiveData and ViewModel, then ask about errors or gaps such as data binding and button handling.

Recommended by 0 people across 0 different months, 2020 to 2022.

What it is

A 36-minute Kotlin tutorial by Reso Coder that builds a small quotes app to demonstrate the MVVM pattern on Android. It uses LiveData, ViewModel, a repository, a fake database and simple manual dependency injection.

What people said

Cites WasimSafdar · 2020-11 · Stack Overflow · on “Not getting a variable name using class instance: Kotlin”

I am following an old tutorial about LiveData and ViewModel.These are the links. [ [this video] ][1] [ [LINK] ] I am getting an error in InjectUtil.kt class while initiating FakeDatabase class and getting it's variable. I am following the tutorial and do not know why I am getting it. //InjectUtil Object package dk.humma.livedata_viewmodel.utilities import dk.humma.livedata_viewmodel.data.FakeDataBase import dk.humma.livedata_viewmodel.data.QuotesRepository import dk.humma.livedata_viewmodel.ui.quotes.QuotesViewModelFactory // Finally a singleton which doesn't need anything passed to the constructor object InjectorUtils { // This will be called from QuotesActivity fun provideQuotesViewModelFactory

Cites jens.svensson · 2021-09 · Stack Overflow · on “How to make button available directly from function”

Hi i am making an app that follows the MVVM structure i took a look at this tutorial [this video] in this tutorial the person that teaches use code that looks like this... private fun initializeUi() { val factory = InjectorUtils.provideQuotesViewModelFactory() val viewModel = ViewModelProviders.of(this, factory) .get(QuotesViewModel::class.java) viewModel.getQuotes().observe(this, Observer { quotes -> val stringBuilder = StringBuilder() quotes.forEach{ quote -> stringBuilder.append("$quote\n\n") } textView_quotes.text = stringBuilder.toString() }) button_add_quote.setOnClickListener { val quote = Quote(editText_quote.text.toString(), editText_author.text.toString()) viewModel.addQuote(quote) edit

Cites peterc · 2022-05 · Stack Overflow · on “Android ViewModel two way binding is not working”

I am trying to learn how to use MVVM, and two way data binding in Android. I am quite familiar with MVVM and two way data binding from other languages/frameworks (.net, Angular etc) So, from what I can see, I want a viewModel to retain data, and I also want a repository that I will be passing to a service (eg to play an audio file) I set up the View model following this tutorial [this video] , but i does cover the UI data binding. I'ev looked at a LOT of posts and doco, and there seems to be a lot of different ways of using ViewModel, so is a bit confusing. In my main activity, I have the following... class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) {