0

Basically I am trying to create an app that passes data filled in an EditText on on one fragment, into a TextView on another fragment on a button click(The buttons is in the first fragment with the EditText). I use the SlidingTabLayout. I have 2 java classes that both extend Fragment and both inflate separate xml layouts(in the onCreateView). I have a java MainActivty with a public class"SectionsPagerAdapter that extends FragmentPagerAdapter, which depending on the swipe of the user displays 1 of the 2 Fragment classes. I am really confused on how I can send data between the 2 fragment sot that from the EditText in 1 fragment can get sent to the TextView in the other fragment on a button click. Could the suggested solutions be explained as simple as possible because I am relatively new to Android Studio. Many thanks in advance.

Harrimf
  • 29
  • 1
  • 1
  • 9
  • You can use Intent to pass data between Activities or you can put data in Bundle to pass it between Fragment , look at this http://stackoverflow.com/a/16036693/4826114 – eddykordo Jul 24 '15 at 08:44

1 Answers1

0

As per my understanding, basically you want to pass data between two fragments.

You can use activity for that from where fragments are initialized.

you can do this.

in MainActivity.java: have a function setData(Object obj) and getData() which returns that object.

From fragment: You can call those function of activity to save your data and get your data. Here's way:

MainActivity activity = (MainActivity) getActivity();
Object obj = activity.getData();
activity.setData(obj);

I hope it helps.

jimish
  • 654
  • 1
  • 8
  • 22