Pass data between 3 fragments or more


I have an application that consists of 3 tabs, the first contains two EditText that receive a URL and send them to the Webview of the second and third tab respectively at the push of a button, or at least that should do, until now I have achieved Send the information from the first tab to the second using an Interface. But I can not manage to send the information of the second EditText to the third tab. Thank you very much for your help.

Here is the code of my MainActivity

public class MainActivity extends AppCompatActivity implements Homefragment.SendMessage1{

TabLayout tabs;
ViewPager pages;
WebAdapter viewPagerAdapter;

protected void onCreate(Bundle savedInstanceState) {
    Toolbar toolbar = findViewById(;

    pages = findViewById(;
    viewPagerAdapter = new WebAdapter(getSupportFragmentManager());
    tabs = findViewById(;

public void sendData1(String message1) {
    String tag1 = "android:switcher:" + + ":" + 1;
    FragmentOne f1 = (FragmentOne) getSupportFragmentManager().findFragmentByTag(tag1);



and here the fragment of the first tab.

public class Homefragment extends Fragment {

SendMessage1 sendMessage1;
SendMessage2 sendMessage2;

public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View rootView = inflater.inflate(
            R.layout.home_fragment, container, false);
    return rootView;


public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    Button btnPassData = view.findViewById(;
    final EditText inData1 = view.findViewById(;
    final EditText inData2 = view.findViewById(;
    btnPassData.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {


interface SendMessage1 {
     void sendData1(String message1);
public void onAttach(Context context) {

    try {
        sendMessage1 = (SendMessage1) getActivity();

    } catch (ClassCastException e) {
        throw new ClassCastException("Error in retrieving data. Please try again");
asked by Alex Hernandez 12.11.2018 в 02:31

0 answers