1

I have two fragments nested within another fragment. One is a list view, and one is a ViewPager, with the viewpager's content being details of a selected list view item. Obviously, they both use the same adapter. The contents of the adapter is refreshed every, say, 5 seconds, so I need to keep the adapter used by both fragments in sync.

What would be the best way to go about keeping the adapter in sync between the two fragments?

I was thinking of storing the adapter in a retained non-ui fragment, making all the update calls within this fragment. This would however require I constantly make pass the updated adapter to the child fragments and call notifyDataSetHasChanged in each fragment

rperryng
  • 3,233
  • 3
  • 22
  • 35
  • 1 use ContentProvider, 2 its query() method retirns a Cursor which is used by a [Simple]CursorAdapter, 3 just pass an Uri between Fragments – pskink Mar 15 '14 at 15:47
  • I am trying to share an adapter between two fragments. a Complex java object. A Content Provider would be nice to share objects that are parcelable or are composed of simple primitives. However this is not the scenario i am in – rperryng Mar 15 '14 at 18:31
  • what Complex object cannot be represented by a Cursor ? – pskink Mar 15 '14 at 18:39
  • It seems I was looking at the default content provider used to manage databases. Anyways, the android developer guides http://developer.android.com/guide/topics/providers/content-provider-creating.html mention that content providers should really only be implemented for use with applications outside of your own. – rperryng Mar 15 '14 at 18:42
  • so if you want not to use a custom CP then create a singleton Adapter and use it wherever you want – pskink Mar 16 '14 at 08:21

0 Answers0