Send data from a fragment to another fragment with nested viewpager - android

how to send data from a fragment that is part of a viewpager, to another fragment that is also in a viewpager. The problem is when in fragment 1 by a spinner select a data, this data has to go to fragment B.

I solved it using RxBus2. Use the Warrenth library. I leave the link to your repoitorio https://github.com/warrenth/RxBus2

Related

How to update listView within the same activity?

Activity A wants to update a listView inside the same activity.
Value is received from a surfaceview - scan, it should not update the listView until the finish button is pressed.
you can use fragments in your activity and then use fragment manager to navigate between your camera page and the listView page.
you can use bundles to share data between these two fragments.
use this to learn more about fragments:
https://developer.android.com/guide/components/fragments
and for sharing data between fragments visit this:
How to pass variables with Android fragmentmanager

Send Data Between two Tab - android

I have create Tabbed activity with two tab
fragment a Contain edittext and fragment b Contain listview ,and I want to send data from fragment a to fragment b ,Please add the code in full,
please help me.
Note : I do not want pass data to textview Iwant to listview
All Fragment-to-Fragment communication is done through the associated Activity. Two Fragments should never communicate directly.
Follow this link

is fine to open a new fragment in fragment?

I want to separate logic fragment from activity but the problem is I make api call and save data in fragment. And when user click a item in fragment. I need to send parcelable data to other fragment to show detail info about item.
Is launching fragment in fragment anti pattern for android ?
I would like to hear some opinion about this matter.
Yes, is totally an anti-pattern, remember that you need to see the Activity as a container and fragments as independent sub-screens, so is the Activity responsibility to manage the fragments. I.e.: If you have a Post activity you can have a PostText fragment, a PostImage fragment and all of that is manage by the activity, every fragment is attached to an Activity.
It is not a common practice to have a nested fragment inside a fragment even it can be done. However, it would be better to have an activity as the centric container for all your fragments. You can use EventBus (GreenRobot / Otto) to separate the concerns and do all the API calls in another class and send the results by subscribing to this event.

Data loading in multiple fragments in ViewPager

I have Activity with ViewPager that holds 3 tabs of Fragments. Each of the fragments has its own URL where it needs to send request and fetch data in JSON format that is shown in Lists in each Fragment.
I am fetching the data in onCreateView and then populating the data in the ListView.
However the ViewPager simultaneously calls onCreateView of both adjacent Fragments due to which the progress bars of multiple Tabs clash and if there is exception in getting data in any one tab it clashes with other tab.
Should the better approach be that i create Objects of Fragments in my Activity and load data in activity and pass on the data to the Fragments as
Fragment one=FragmentOne.getInstance();
Fragment two=FragmentTwo.getInstance();
and after obtaining data ->
one.setData(Data)
two.setData(Data)
If anyone can guide how to do the same.
Thanks

Transaction between Fragment and Activity

I have a fragment and an activity.there are some fields and an button in fragment.When i click an button in fragment then i want to go to an activity.In that activity i have another button.when i click on that button i want to return from the present activity to the previous fragment.Every thing works fine.what i need is i want to recreate the fragment when i return to the fragment from the activity..i.e,for example in the fragment if i enter anything in the edit_text before passing to the activity, which is also presented when i returned from the activity.(the fragment is same as how i left from fragment) which is i don't want .i want a fresh page.i want to recreate a fragment when i returned from activity ..i need to select fields newly..can any one suggest any help..thanks in advance..
Try to use main FragmentActivity and Fragments and organize transactions between fragments. I didn't meet examples with Activity and Fragment in one Addlication.

Categories

Resources