Search code examples
androidandroid-gridviewandroid-tabs

Populating 3 tabs with a single network call


Suppose I have 3 tabs each populated by separate fragments (containing a grid view). Lets say a single network call gives me the JSON data to populate all 3 tabs.

Assuming, there is no local database, how do I go about implementing this ? ie populating the 3 tabs from a single network call ?

I'm looking for the logic on how to implement this, rather than the code.

Thanks

EDIT:

Forgot to mention that I have the model of each element in the gridview predefined.


Solution

  • You can achieve it in a lot of ways here is one:

    1) Create a network call on the main activity

    2) When receiving the result send your result by LocalBroadcastManager to your fragments.(Note that your model must implement Parcelable interface so you can put the data to the intent)

    3) In each fragment create a BroadcastReceiver and in onReceive extract the data and update the UI.