Retrieve Fragments EditText in Activity

2

I have an Activity with Actionbar and three Tabs, in each Tab a different Fragment is loaded and in each fragment of that I have a form. When I finish filling out all three forms, when I tap the save button I want to be able to retrieve the information for each fragment and persist in SQLite.

My question is how do I access the fields of each fragment.

I've tried using

Fragment1 detalhes = (Fragment1) fragmentManager.findFragmentByTag("frag1");

but only works to retrieve the field in the current fragment. How do I recover from everyone?

    
asked by anonymous 09.03.2014 / 17:35

2 answers

0

When you move from one fragment to the other you will have to send the data that has been filled to the other so you do not lose.

For example, create a class with all form fields represented as attributes. When you switch from fragment A to B, you pick up all the data that has been entered on the screen and play to the class you created. In fragment B you will receive this data and will add more data that has been informed now.

This way you can go back and forth on the screen swap and will always keep the data. When you get to the last fragment, when you click Save, you just take the data from the transport class and persist it.

    
10.03.2014 / 16:54
0

A simple solution to keep data between fragment transitions is from the setOffscreenPageLimit() method. Where the number of screens is passed as parameter, in the example below the data will be kept between 3 screens.

Important to stress the greatest memory consumption.

    viewPager.setOffscreenPageLimit(3);
    
16.09.2015 / 21:34