Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

getting data from snapshot in Activity to fragments in the viewpager

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys

Please help, I have been looking for information on:

I have an activity with a viewpager, that gets a snapshot from Firebase database(the snapshot is gotten from the activity), and would like to pass the data from the activity to the fragments in the view pager..

How would I do this please?

Thanks...
 
Saloon Keeper
Posts: 5765
146
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you have a FragmentPagerAdapter, you could have keep track of all fragments, and through it pass data to them.

Alternatively, you could use an event bus like https://github.com/greenrobot/EventBus to post the data to whoever needs them.
 
Ben van Jaarsveld
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can't I just pass the information when I add the Fragment to the viewpager in the activity?:



like this?

in activities it is easy, I just use getExtra...so is there no way that I can just ask for a String to be passed from the Activity?
 
Tim Moores
Saloon Keeper
Posts: 5765
146
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can pass any information whatsoever in the constructor. I thought the data you mentioned were not known at the time of construction ... not so?
 
Ben van Jaarsveld
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Moores wrote:You can pass any information whatsoever in the constructor. I thought the data you mentioned were not known at the time of construction ... not so?



Yes you are right...oops...

I think I found a way:



trying it out as we speak(or type)...
 
Ben van Jaarsveld
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't seem to make it work,

In my activity I have 5 fragments in my viewpager... the idea is to only request 1 datasnapshot in the activity and then pass all the data I need to the different fragments...

this will save data and power ....

 
What could go wrong in a swell place like "The Evil Eye"? Or with this tiny ad?
create, convert, edit or print DOC and DOCX in Java
https://products.aspose.com/words/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!