How to display progress using ProgessDialog in MVVM
Asked Answered
P

1

6

I wrote an Android app using MVVM where I am calling webservice from ViewModel and storing results in RoomDB. In the View I am observing ViewModel for live data. I need to show ProgressDialog while fetching data from Webservice using Retrofit. Where do I need to write code to display progressdialog as I should not use userinterface widgets in other architecture components except in View component? Can anyone help me how to handle this scenario?

Thanks in Advance.

Paba answered 10/7, 2018 at 10:23 Comment(0)
B
-1

Yes, you can do it by calling a dialog from the activity and hide dialog in view model observer. This is how I have handled the progress dialog in my view.

Code::

    private fun callWebApi() {
    // show progress dialog 
    showLoader()

    mViewModel?.loadMethod()
        ?.observe(this, Observer { mModel: BaseModel? ->
            // hide loader
            hideLoader()
            // implement code
        })
    }
}
Bleachers answered 10/7, 2018 at 10:57 Comment(1)
I don't think this is the right way. as you're dismissing alert dialog every now and then when data changesHistrionic

© 2022 - 2024 — McMap. All rights reserved.