https://kotlinlang.org logo
#android
Title
# android
c

Cyberpunk Keanu

11/22/2019, 10:58 AM
Anyone know how do I fix this? I'm receiving data in the detail activity using retrofit request, & send that data to the 4 tabs in my viewpager with View Model Now when the Activity loads, it has to also load the viewpager along with the first fragment which is displayed in the start. But problem is, making the request call & get the data, pass it to viewmodel, get data from the viewmodel takes some time I guess. Until then, the first fragment is already loaded without the items in my recyclerview. How do I automatically refresh the first fragment in the viewpager when my data has been fetched?
s

Shaishav

11/22/2019, 12:02 PM
Not sure what architecture you’re using but, to put simply you need some kind of callback interface that your View can implement. Your data loaders can then call these interface events appropriately.
I believe you’re fetching data from a backend server but, you aren’t showing loaders of any sorts. Till the time data is being loaded user should be shown that. Also, assume the backend server will fail (even n/w errors) so, incorporate UI for that too if not done already.
c

Cyberpunk Keanu

11/22/2019, 12:06 PM
Yes, I'm fetching the data with a retrofit request. Right now the app is still in early development, we just want to make sure that everything's working properly. Handling the UI use cases is something we'll look after later.
s

Shaishav

11/22/2019, 12:10 PM
So, the user needs to wait till data is fetched. When it is indeed fetched, as the most basic plug - just fire an Event that the data is loaded (via EventBus maybe). Tbh, the optimal answer will depend on your app architecture.
s

Shrikant

11/22/2019, 1:41 PM
If you are using ViewModel-LiveData, I would suggest to use LiveData to observe states before and after getting data from network call. As @Shaishav said, it will varies upon the architecture you use.
m

Mohammed Alaa

11/22/2019, 8:13 PM
If your data load in Detail activity result from API call then in the succes of the API call create your viewpager and set it's data , I think this should work
6 Views