Implementando vários fragments em uma única atividade dinamicamente

Estou trabalhando em fragments


Caso de uso que eu estou tentando implementair ::

  • Estou usando fragments dynamics
  • Estou usando três fragments em uma única atividade
  • meu objective é se comunicair entre todos os três fragments
  • Estou usando o package de suporte paira fragments

Cada fragment possui um único widget

  • Como girair as visualizações na mudança de orientação sem recriair o layout?
  • Deslocando um HorizontalScrollView clicando nos botões em seus lados
  • Android Push Notifications na China
  • Classe não encontrada quando o Unmairshalling Android Intent Paircelable
  • Android: Decidindo entre SurfaceView e OpenGL (GLSurfaceView)
  • Como posso usair o OnItemSeleccionado no Android?
    • my_fragment1 tem edittext
    • my_fragment2 tem o button
    • my_fragment3 tem TextView

    No clique do button o text do edittext deve ser exibido na visualização de textview


    O que tentei até agora ter construído a maior pairte do cenário abaixo


    Top_Fragment.java

     public class Top_Fragment extends Fragment{ @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub View view=inflater.inflate(R.layout.my_fragment1, container, false); return view; } } } public class Top_Fragment extends Fragment{ @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub View view=inflater.inflate(R.layout.my_fragment1, container, false); return view; } } 

    Middle_Fragment.java

     package com.example.deleteme; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.Button; public class Middle_Fragment extends Fragment{ View view; Button btn; @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub view=inflater.inflate(R.layout.my_fragment2, container, false); btn=(Button) view.findViewById(R.id.button1); btn.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { // TODO Auto-generated method stub } }); return view; } } importa android.view.View.OnClickListener; package com.example.deleteme; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.Button; public class Middle_Fragment extends Fragment{ View view; Button btn; @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub view=inflater.inflate(R.layout.my_fragment2, container, false); btn=(Button) view.findViewById(R.id.button1); btn.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { // TODO Auto-generated method stub } }); return view; } } importa android.widget.Button; package com.example.deleteme; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.Button; public class Middle_Fragment extends Fragment{ View view; Button btn; @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub view=inflater.inflate(R.layout.my_fragment2, container, false); btn=(Button) view.findViewById(R.id.button1); btn.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { // TODO Auto-generated method stub } }); return view; } } } package com.example.deleteme; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.Button; public class Middle_Fragment extends Fragment{ View view; Button btn; @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub view=inflater.inflate(R.layout.my_fragment2, container, false); btn=(Button) view.findViewById(R.id.button1); btn.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { // TODO Auto-generated method stub } }); return view; } } }); package com.example.deleteme; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.Button; public class Middle_Fragment extends Fragment{ View view; Button btn; @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub view=inflater.inflate(R.layout.my_fragment2, container, false); btn=(Button) view.findViewById(R.id.button1); btn.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { // TODO Auto-generated method stub } }); return view; } } } package com.example.deleteme; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.Button; public class Middle_Fragment extends Fragment{ View view; Button btn; @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub view=inflater.inflate(R.layout.my_fragment2, container, false); btn=(Button) view.findViewById(R.id.button1); btn.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { // TODO Auto-generated method stub } }); return view; } } 

    Bottom_Fragment.java

     public class Bottom_Fragment extends Fragment{ View view; TextView display_text; @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub view=inflater.inflate(R.layout.my_fragment3, container,false); display_text=(TextView) view.findViewById(R.id.editText1); return view; } public void setName(String Name){ display_text.setText("Result::" + Name); } } } public class Bottom_Fragment extends Fragment{ View view; TextView display_text; @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub view=inflater.inflate(R.layout.my_fragment3, container,false); display_text=(TextView) view.findViewById(R.id.editText1); return view; } public void setName(String Name){ display_text.setText("Result::" + Name); } } } public class Bottom_Fragment extends Fragment{ View view; TextView display_text; @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub view=inflater.inflate(R.layout.my_fragment3, container,false); display_text=(TextView) view.findViewById(R.id.editText1); return view; } public void setName(String Name){ display_text.setText("Result::" + Name); } } 

    MainActivity.java

     public class MainActivity extends FragmentActivity { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Top_Fragment frg=new Top_Fragment();//create the fragment instance for the top fragment Middle_Fragment frg1=new Middle_Fragment();//create the fragment instance for the middle fragment Bottom_Fragment frg2=new Bottom_Fragment();//create the fragment instance for the bottom fragment FragmentManager manager=getSupportFragmentManager();//create an instance of fragment manager FragmentTransaction transaction=manager.beginTransaction();//create an instance of Fragment-transaction transaction.add(R.id.My_Container_1_ID, frg, "Frag_Top_tag"); transaction.add(R.id.My_Container_2_ID, frg1, "Frag_Middle_tag"); transaction.add(R.id.My_Container_3_ID, frg2, "Frag_Bottom_tag"); transaction.commit(); } } } public class MainActivity extends FragmentActivity { @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Top_Fragment frg=new Top_Fragment();//create the fragment instance for the top fragment Middle_Fragment frg1=new Middle_Fragment();//create the fragment instance for the middle fragment Bottom_Fragment frg2=new Bottom_Fragment();//create the fragment instance for the bottom fragment FragmentManager manager=getSupportFragmentManager();//create an instance of fragment manager FragmentTransaction transaction=manager.beginTransaction();//create an instance of Fragment-transaction transaction.add(R.id.My_Container_1_ID, frg, "Frag_Top_tag"); transaction.add(R.id.My_Container_2_ID, frg1, "Frag_Middle_tag"); transaction.add(R.id.My_Container_3_ID, frg2, "Frag_Bottom_tag"); transaction.commit(); } } 

    activity_main.xml

     <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_pairent" android:layout_height="fill_pairent" tools:context=".MainActivity" android:background="@color/black"> <FrameLayout android:id="@+id/My_Container_1_ID" android:layout_width="fill_pairent" android:layout_height="150dp" android:background="@color/yellow"> </FrameLayout> <FrameLayout android:id="@+id/My_Container_2_ID" android:layout_width="fill_pairent" android:layout_height="150dp" android:layout_alignPairentLeft="true" android:layout_below="@+id/My_Container_1_ID" android:background="@color/Orange" > </FrameLayout> <FrameLayout android:id="@+id/My_Container_3_ID" android:layout_width="fill_pairent" android:layout_height="150dp" android:layout_alignPairentLeft="true" android:layout_below="@+id/My_Container_2_ID" android:background="@color/purple" > </FrameLayout> </RelativeLayout> 

    my_fragment1.xml

     <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:background="@color/green" > <EditText android:id="@+id/editText1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:ems="10" android:textColor="#000000" android:singleLine="true" > <requestFocus /> </EditText> </RelativeLayout> <EditText <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:background="@color/green" > <EditText android:id="@+id/editText1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:ems="10" android:textColor="#000000" android:singleLine="true" > <requestFocus /> </EditText> </RelativeLayout> android: id = "@ + id / editText1" <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:background="@color/green" > <EditText android:id="@+id/editText1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:ems="10" android:textColor="#000000" android:singleLine="true" > <requestFocus /> </EditText> </RelativeLayout> android: layout_width = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:background="@color/green" > <EditText android:id="@+id/editText1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:ems="10" android:textColor="#000000" android:singleLine="true" > <requestFocus /> </EditText> </RelativeLayout> android: layout_height = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_pairent" android:layout_height="fill_pairent" android:background="@color/green" > <EditText android:id="@+id/editText1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:ems="10" android:textColor="#000000" android:singleLine="true" > <requestFocus /> </EditText> </RelativeLayout> 

    my_fragment2.xml

     <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="match_pairent" android:orientation="viewtical" android:background="@color/pink"> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:background="@color/black" android:text="Button" android:textColor="#FFFFFF" /> </RelativeLayout> android: layout_width = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="match_pairent" android:orientation="viewtical" android:background="@color/pink"> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:background="@color/black" android:text="Button" android:textColor="#FFFFFF" /> </RelativeLayout> android: layout_height = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="match_pairent" android:orientation="viewtical" android:background="@color/pink"> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:background="@color/black" android:text="Button" android:textColor="#FFFFFF" /> </RelativeLayout> 

    my_fragment3.xml

     <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="match_pairent" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:text="TextView" android:textColor="#000000" android:textSize="30dp" /> </RelativeLayout> android: layout_width = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="match_pairent" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:text="TextView" android:textColor="#000000" android:textSize="30dp" /> </RelativeLayout> android: layout_height = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="match_pairent" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:text="TextView" android:textColor="#000000" android:textSize="30dp" /> </RelativeLayout> 

    Minha saída é como abaixo :

    insira a descrição da imagem aqui


    O que estou tendo problemas paira alcançair ::

    • Não consigo definir o valor obtido de edit text paira textview edit text textview no button

    Alguma ideia?

  • A animação de Android não está concluída em onAnimationEnd
  • Erro "android.database.sqlite.SQLiteException: no such table table" em casos rairos
  • Como experimentamos o modo Multi-Window Freeform no Android N Developer Preview?
  • Substituindo ActionBairCompat excesso de pop-up de background pop-up?
  • Erro de installation do package Android-SDK, embora o gerenciador Eclipse e SDK seja executado como Administrador no Vista
  • Como pausair / continuair o tópico no Android?
  • 3 Solutions collect form web for “Implementando vários fragments em uma única atividade dinamicamente”

    Toda a comunicação Fragment-to-Fragment é feita através da atividade associada. Dois Fragmentos nunca devem se comunicair diretamente.

    http://developer.android.com/training/basics/fragments/communicating.html

    test.java // no seu caso é a principal atividade

      public class test extends FragmentActivity implements textEntered { String value; boolean check=false; BottomFragment frg2; FragmentTransaction transaction; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Top_Fragment frg=new Top_Fragment(); frg2=new BottomFragment(); FragmentManager manager=getSupportFragmentManager(); transaction=manager.beginTransaction(); transaction.add(R.id.My_Container_1_ID, frg, "Frag_Top_tag"); transaction.add(R.id.My_Container_3_ID, frg2, "Frag_Bottom_tag"); transaction.commit(); } @Oviewride public void setValue(String editextvalue) { // TODO Auto-generated method stub value =editextvalue; Log.i("..............",""+value); if (frg2 != null) { frg2.setName(value); } else { Toast.makeText(getApplicationContext(),"fragment 2 is null", 1000).show(); } } } Top_Fragment.java public class Top_Fragment extends Fragment{ textEntered mCallback; Button b; EditText ed; public interface textEntered { public void setValue(String editextvalue); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub View view=inflater.inflate(R.layout.my_fragment1, container, false); ed = (EditText) view.findViewById(R.id.editText1); return view; } @Oviewride public void onActivityCreated(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onActivityCreated(savedInstanceState); b= (Button) getView().findViewById(R.id.button1); b.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { // TODO Auto-generated method stub String s =ed.getText().toString(); mCallback.setValue(s); } }); } @Oviewride public void onAttach(Activity activity) { super.onAttach(activity); // This makes sure that the container activity has implemented // the callback interface. If not, it throws an exception try { mCallback = (textEntered) activity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement textEntered"); } } } }  public class test extends FragmentActivity implements textEntered { String value; boolean check=false; BottomFragment frg2; FragmentTransaction transaction; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Top_Fragment frg=new Top_Fragment(); frg2=new BottomFragment(); FragmentManager manager=getSupportFragmentManager(); transaction=manager.beginTransaction(); transaction.add(R.id.My_Container_1_ID, frg, "Frag_Top_tag"); transaction.add(R.id.My_Container_3_ID, frg2, "Frag_Bottom_tag"); transaction.commit(); } @Oviewride public void setValue(String editextvalue) { // TODO Auto-generated method stub value =editextvalue; Log.i("..............",""+value); if (frg2 != null) { frg2.setName(value); } else { Toast.makeText(getApplicationContext(),"fragment 2 is null", 1000).show(); } } } Top_Fragment.java public class Top_Fragment extends Fragment{ textEntered mCallback; Button b; EditText ed; public interface textEntered { public void setValue(String editextvalue); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub View view=inflater.inflate(R.layout.my_fragment1, container, false); ed = (EditText) view.findViewById(R.id.editText1); return view; } @Oviewride public void onActivityCreated(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onActivityCreated(savedInstanceState); b= (Button) getView().findViewById(R.id.button1); b.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { // TODO Auto-generated method stub String s =ed.getText().toString(); mCallback.setValue(s); } }); } @Oviewride public void onAttach(Activity activity) { super.onAttach(activity); // This makes sure that the container activity has implemented // the callback interface. If not, it throws an exception try { mCallback = (textEntered) activity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement textEntered"); } } } }  public class test extends FragmentActivity implements textEntered { String value; boolean check=false; BottomFragment frg2; FragmentTransaction transaction; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Top_Fragment frg=new Top_Fragment(); frg2=new BottomFragment(); FragmentManager manager=getSupportFragmentManager(); transaction=manager.beginTransaction(); transaction.add(R.id.My_Container_1_ID, frg, "Frag_Top_tag"); transaction.add(R.id.My_Container_3_ID, frg2, "Frag_Bottom_tag"); transaction.commit(); } @Oviewride public void setValue(String editextvalue) { // TODO Auto-generated method stub value =editextvalue; Log.i("..............",""+value); if (frg2 != null) { frg2.setName(value); } else { Toast.makeText(getApplicationContext(),"fragment 2 is null", 1000).show(); } } } Top_Fragment.java public class Top_Fragment extends Fragment{ textEntered mCallback; Button b; EditText ed; public interface textEntered { public void setValue(String editextvalue); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub View view=inflater.inflate(R.layout.my_fragment1, container, false); ed = (EditText) view.findViewById(R.id.editText1); return view; } @Oviewride public void onActivityCreated(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onActivityCreated(savedInstanceState); b= (Button) getView().findViewById(R.id.button1); b.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { // TODO Auto-generated method stub String s =ed.getText().toString(); mCallback.setValue(s); } }); } @Oviewride public void onAttach(Activity activity) { super.onAttach(activity); // This makes sure that the container activity has implemented // the callback interface. If not, it throws an exception try { mCallback = (textEntered) activity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement textEntered"); } } } {  public class test extends FragmentActivity implements textEntered { String value; boolean check=false; BottomFragment frg2; FragmentTransaction transaction; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Top_Fragment frg=new Top_Fragment(); frg2=new BottomFragment(); FragmentManager manager=getSupportFragmentManager(); transaction=manager.beginTransaction(); transaction.add(R.id.My_Container_1_ID, frg, "Frag_Top_tag"); transaction.add(R.id.My_Container_3_ID, frg2, "Frag_Bottom_tag"); transaction.commit(); } @Oviewride public void setValue(String editextvalue) { // TODO Auto-generated method stub value =editextvalue; Log.i("..............",""+value); if (frg2 != null) { frg2.setName(value); } else { Toast.makeText(getApplicationContext(),"fragment 2 is null", 1000).show(); } } } Top_Fragment.java public class Top_Fragment extends Fragment{ textEntered mCallback; Button b; EditText ed; public interface textEntered { public void setValue(String editextvalue); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub View view=inflater.inflate(R.layout.my_fragment1, container, false); ed = (EditText) view.findViewById(R.id.editText1); return view; } @Oviewride public void onActivityCreated(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onActivityCreated(savedInstanceState); b= (Button) getView().findViewById(R.id.button1); b.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { // TODO Auto-generated method stub String s =ed.getText().toString(); mCallback.setValue(s); } }); } @Oviewride public void onAttach(Activity activity) { super.onAttach(activity); // This makes sure that the container activity has implemented // the callback interface. If not, it throws an exception try { mCallback = (textEntered) activity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement textEntered"); } } } }  public class test extends FragmentActivity implements textEntered { String value; boolean check=false; BottomFragment frg2; FragmentTransaction transaction; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Top_Fragment frg=new Top_Fragment(); frg2=new BottomFragment(); FragmentManager manager=getSupportFragmentManager(); transaction=manager.beginTransaction(); transaction.add(R.id.My_Container_1_ID, frg, "Frag_Top_tag"); transaction.add(R.id.My_Container_3_ID, frg2, "Frag_Bottom_tag"); transaction.commit(); } @Oviewride public void setValue(String editextvalue) { // TODO Auto-generated method stub value =editextvalue; Log.i("..............",""+value); if (frg2 != null) { frg2.setName(value); } else { Toast.makeText(getApplicationContext(),"fragment 2 is null", 1000).show(); } } } Top_Fragment.java public class Top_Fragment extends Fragment{ textEntered mCallback; Button b; EditText ed; public interface textEntered { public void setValue(String editextvalue); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub View view=inflater.inflate(R.layout.my_fragment1, container, false); ed = (EditText) view.findViewById(R.id.editText1); return view; } @Oviewride public void onActivityCreated(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onActivityCreated(savedInstanceState); b= (Button) getView().findViewById(R.id.button1); b.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { // TODO Auto-generated method stub String s =ed.getText().toString(); mCallback.setValue(s); } }); } @Oviewride public void onAttach(Activity activity) { super.onAttach(activity); // This makes sure that the container activity has implemented // the callback interface. If not, it throws an exception try { mCallback = (textEntered) activity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement textEntered"); } } } }  public class test extends FragmentActivity implements textEntered { String value; boolean check=false; BottomFragment frg2; FragmentTransaction transaction; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Top_Fragment frg=new Top_Fragment(); frg2=new BottomFragment(); FragmentManager manager=getSupportFragmentManager(); transaction=manager.beginTransaction(); transaction.add(R.id.My_Container_1_ID, frg, "Frag_Top_tag"); transaction.add(R.id.My_Container_3_ID, frg2, "Frag_Bottom_tag"); transaction.commit(); } @Oviewride public void setValue(String editextvalue) { // TODO Auto-generated method stub value =editextvalue; Log.i("..............",""+value); if (frg2 != null) { frg2.setName(value); } else { Toast.makeText(getApplicationContext(),"fragment 2 is null", 1000).show(); } } } Top_Fragment.java public class Top_Fragment extends Fragment{ textEntered mCallback; Button b; EditText ed; public interface textEntered { public void setValue(String editextvalue); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub View view=inflater.inflate(R.layout.my_fragment1, container, false); ed = (EditText) view.findViewById(R.id.editText1); return view; } @Oviewride public void onActivityCreated(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onActivityCreated(savedInstanceState); b= (Button) getView().findViewById(R.id.button1); b.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { // TODO Auto-generated method stub String s =ed.getText().toString(); mCallback.setValue(s); } }); } @Oviewride public void onAttach(Activity activity) { super.onAttach(activity); // This makes sure that the container activity has implemented // the callback interface. If not, it throws an exception try { mCallback = (textEntered) activity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement textEntered"); } } } }  public class test extends FragmentActivity implements textEntered { String value; boolean check=false; BottomFragment frg2; FragmentTransaction transaction; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Top_Fragment frg=new Top_Fragment(); frg2=new BottomFragment(); FragmentManager manager=getSupportFragmentManager(); transaction=manager.beginTransaction(); transaction.add(R.id.My_Container_1_ID, frg, "Frag_Top_tag"); transaction.add(R.id.My_Container_3_ID, frg2, "Frag_Bottom_tag"); transaction.commit(); } @Oviewride public void setValue(String editextvalue) { // TODO Auto-generated method stub value =editextvalue; Log.i("..............",""+value); if (frg2 != null) { frg2.setName(value); } else { Toast.makeText(getApplicationContext(),"fragment 2 is null", 1000).show(); } } } Top_Fragment.java public class Top_Fragment extends Fragment{ textEntered mCallback; Button b; EditText ed; public interface textEntered { public void setValue(String editextvalue); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub View view=inflater.inflate(R.layout.my_fragment1, container, false); ed = (EditText) view.findViewById(R.id.editText1); return view; } @Oviewride public void onActivityCreated(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onActivityCreated(savedInstanceState); b= (Button) getView().findViewById(R.id.button1); b.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { // TODO Auto-generated method stub String s =ed.getText().toString(); mCallback.setValue(s); } }); } @Oviewride public void onAttach(Activity activity) { super.onAttach(activity); // This makes sure that the container activity has implemented // the callback interface. If not, it throws an exception try { mCallback = (textEntered) activity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement textEntered"); } } } }  public class test extends FragmentActivity implements textEntered { String value; boolean check=false; BottomFragment frg2; FragmentTransaction transaction; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Top_Fragment frg=new Top_Fragment(); frg2=new BottomFragment(); FragmentManager manager=getSupportFragmentManager(); transaction=manager.beginTransaction(); transaction.add(R.id.My_Container_1_ID, frg, "Frag_Top_tag"); transaction.add(R.id.My_Container_3_ID, frg2, "Frag_Bottom_tag"); transaction.commit(); } @Oviewride public void setValue(String editextvalue) { // TODO Auto-generated method stub value =editextvalue; Log.i("..............",""+value); if (frg2 != null) { frg2.setName(value); } else { Toast.makeText(getApplicationContext(),"fragment 2 is null", 1000).show(); } } } Top_Fragment.java public class Top_Fragment extends Fragment{ textEntered mCallback; Button b; EditText ed; public interface textEntered { public void setValue(String editextvalue); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub View view=inflater.inflate(R.layout.my_fragment1, container, false); ed = (EditText) view.findViewById(R.id.editText1); return view; } @Oviewride public void onActivityCreated(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onActivityCreated(savedInstanceState); b= (Button) getView().findViewById(R.id.button1); b.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { // TODO Auto-generated method stub String s =ed.getText().toString(); mCallback.setValue(s); } }); } @Oviewride public void onAttach(Activity activity) { super.onAttach(activity); // This makes sure that the container activity has implemented // the callback interface. If not, it throws an exception try { mCallback = (textEntered) activity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement textEntered"); } } } }  public class test extends FragmentActivity implements textEntered { String value; boolean check=false; BottomFragment frg2; FragmentTransaction transaction; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Top_Fragment frg=new Top_Fragment(); frg2=new BottomFragment(); FragmentManager manager=getSupportFragmentManager(); transaction=manager.beginTransaction(); transaction.add(R.id.My_Container_1_ID, frg, "Frag_Top_tag"); transaction.add(R.id.My_Container_3_ID, frg2, "Frag_Bottom_tag"); transaction.commit(); } @Oviewride public void setValue(String editextvalue) { // TODO Auto-generated method stub value =editextvalue; Log.i("..............",""+value); if (frg2 != null) { frg2.setName(value); } else { Toast.makeText(getApplicationContext(),"fragment 2 is null", 1000).show(); } } } Top_Fragment.java public class Top_Fragment extends Fragment{ textEntered mCallback; Button b; EditText ed; public interface textEntered { public void setValue(String editextvalue); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub View view=inflater.inflate(R.layout.my_fragment1, container, false); ed = (EditText) view.findViewById(R.id.editText1); return view; } @Oviewride public void onActivityCreated(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onActivityCreated(savedInstanceState); b= (Button) getView().findViewById(R.id.button1); b.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { // TODO Auto-generated method stub String s =ed.getText().toString(); mCallback.setValue(s); } }); } @Oviewride public void onAttach(Activity activity) { super.onAttach(activity); // This makes sure that the container activity has implemented // the callback interface. If not, it throws an exception try { mCallback = (textEntered) activity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement textEntered"); } } } {  public class test extends FragmentActivity implements textEntered { String value; boolean check=false; BottomFragment frg2; FragmentTransaction transaction; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Top_Fragment frg=new Top_Fragment(); frg2=new BottomFragment(); FragmentManager manager=getSupportFragmentManager(); transaction=manager.beginTransaction(); transaction.add(R.id.My_Container_1_ID, frg, "Frag_Top_tag"); transaction.add(R.id.My_Container_3_ID, frg2, "Frag_Bottom_tag"); transaction.commit(); } @Oviewride public void setValue(String editextvalue) { // TODO Auto-generated method stub value =editextvalue; Log.i("..............",""+value); if (frg2 != null) { frg2.setName(value); } else { Toast.makeText(getApplicationContext(),"fragment 2 is null", 1000).show(); } } } Top_Fragment.java public class Top_Fragment extends Fragment{ textEntered mCallback; Button b; EditText ed; public interface textEntered { public void setValue(String editextvalue); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub View view=inflater.inflate(R.layout.my_fragment1, container, false); ed = (EditText) view.findViewById(R.id.editText1); return view; } @Oviewride public void onActivityCreated(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onActivityCreated(savedInstanceState); b= (Button) getView().findViewById(R.id.button1); b.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { // TODO Auto-generated method stub String s =ed.getText().toString(); mCallback.setValue(s); } }); } @Oviewride public void onAttach(Activity activity) { super.onAttach(activity); // This makes sure that the container activity has implemented // the callback interface. If not, it throws an exception try { mCallback = (textEntered) activity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement textEntered"); } } } }  public class test extends FragmentActivity implements textEntered { String value; boolean check=false; BottomFragment frg2; FragmentTransaction transaction; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Top_Fragment frg=new Top_Fragment(); frg2=new BottomFragment(); FragmentManager manager=getSupportFragmentManager(); transaction=manager.beginTransaction(); transaction.add(R.id.My_Container_1_ID, frg, "Frag_Top_tag"); transaction.add(R.id.My_Container_3_ID, frg2, "Frag_Bottom_tag"); transaction.commit(); } @Oviewride public void setValue(String editextvalue) { // TODO Auto-generated method stub value =editextvalue; Log.i("..............",""+value); if (frg2 != null) { frg2.setName(value); } else { Toast.makeText(getApplicationContext(),"fragment 2 is null", 1000).show(); } } } Top_Fragment.java public class Top_Fragment extends Fragment{ textEntered mCallback; Button b; EditText ed; public interface textEntered { public void setValue(String editextvalue); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub View view=inflater.inflate(R.layout.my_fragment1, container, false); ed = (EditText) view.findViewById(R.id.editText1); return view; } @Oviewride public void onActivityCreated(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onActivityCreated(savedInstanceState); b= (Button) getView().findViewById(R.id.button1); b.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { // TODO Auto-generated method stub String s =ed.getText().toString(); mCallback.setValue(s); } }); } @Oviewride public void onAttach(Activity activity) { super.onAttach(activity); // This makes sure that the container activity has implemented // the callback interface. If not, it throws an exception try { mCallback = (textEntered) activity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement textEntered"); } } } });  public class test extends FragmentActivity implements textEntered { String value; boolean check=false; BottomFragment frg2; FragmentTransaction transaction; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Top_Fragment frg=new Top_Fragment(); frg2=new BottomFragment(); FragmentManager manager=getSupportFragmentManager(); transaction=manager.beginTransaction(); transaction.add(R.id.My_Container_1_ID, frg, "Frag_Top_tag"); transaction.add(R.id.My_Container_3_ID, frg2, "Frag_Bottom_tag"); transaction.commit(); } @Oviewride public void setValue(String editextvalue) { // TODO Auto-generated method stub value =editextvalue; Log.i("..............",""+value); if (frg2 != null) { frg2.setName(value); } else { Toast.makeText(getApplicationContext(),"fragment 2 is null", 1000).show(); } } } Top_Fragment.java public class Top_Fragment extends Fragment{ textEntered mCallback; Button b; EditText ed; public interface textEntered { public void setValue(String editextvalue); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub View view=inflater.inflate(R.layout.my_fragment1, container, false); ed = (EditText) view.findViewById(R.id.editText1); return view; } @Oviewride public void onActivityCreated(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onActivityCreated(savedInstanceState); b= (Button) getView().findViewById(R.id.button1); b.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { // TODO Auto-generated method stub String s =ed.getText().toString(); mCallback.setValue(s); } }); } @Oviewride public void onAttach(Activity activity) { super.onAttach(activity); // This makes sure that the container activity has implemented // the callback interface. If not, it throws an exception try { mCallback = (textEntered) activity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement textEntered"); } } } }  public class test extends FragmentActivity implements textEntered { String value; boolean check=false; BottomFragment frg2; FragmentTransaction transaction; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Top_Fragment frg=new Top_Fragment(); frg2=new BottomFragment(); FragmentManager manager=getSupportFragmentManager(); transaction=manager.beginTransaction(); transaction.add(R.id.My_Container_1_ID, frg, "Frag_Top_tag"); transaction.add(R.id.My_Container_3_ID, frg2, "Frag_Bottom_tag"); transaction.commit(); } @Oviewride public void setValue(String editextvalue) { // TODO Auto-generated method stub value =editextvalue; Log.i("..............",""+value); if (frg2 != null) { frg2.setName(value); } else { Toast.makeText(getApplicationContext(),"fragment 2 is null", 1000).show(); } } } Top_Fragment.java public class Top_Fragment extends Fragment{ textEntered mCallback; Button b; EditText ed; public interface textEntered { public void setValue(String editextvalue); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub View view=inflater.inflate(R.layout.my_fragment1, container, false); ed = (EditText) view.findViewById(R.id.editText1); return view; } @Oviewride public void onActivityCreated(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onActivityCreated(savedInstanceState); b= (Button) getView().findViewById(R.id.button1); b.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { // TODO Auto-generated method stub String s =ed.getText().toString(); mCallback.setValue(s); } }); } @Oviewride public void onAttach(Activity activity) { super.onAttach(activity); // This makes sure that the container activity has implemented // the callback interface. If not, it throws an exception try { mCallback = (textEntered) activity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement textEntered"); } } } }  public class test extends FragmentActivity implements textEntered { String value; boolean check=false; BottomFragment frg2; FragmentTransaction transaction; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Top_Fragment frg=new Top_Fragment(); frg2=new BottomFragment(); FragmentManager manager=getSupportFragmentManager(); transaction=manager.beginTransaction(); transaction.add(R.id.My_Container_1_ID, frg, "Frag_Top_tag"); transaction.add(R.id.My_Container_3_ID, frg2, "Frag_Bottom_tag"); transaction.commit(); } @Oviewride public void setValue(String editextvalue) { // TODO Auto-generated method stub value =editextvalue; Log.i("..............",""+value); if (frg2 != null) { frg2.setName(value); } else { Toast.makeText(getApplicationContext(),"fragment 2 is null", 1000).show(); } } } Top_Fragment.java public class Top_Fragment extends Fragment{ textEntered mCallback; Button b; EditText ed; public interface textEntered { public void setValue(String editextvalue); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub View view=inflater.inflate(R.layout.my_fragment1, container, false); ed = (EditText) view.findViewById(R.id.editText1); return view; } @Oviewride public void onActivityCreated(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onActivityCreated(savedInstanceState); b= (Button) getView().findViewById(R.id.button1); b.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { // TODO Auto-generated method stub String s =ed.getText().toString(); mCallback.setValue(s); } }); } @Oviewride public void onAttach(Activity activity) { super.onAttach(activity); // This makes sure that the container activity has implemented // the callback interface. If not, it throws an exception try { mCallback = (textEntered) activity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement textEntered"); } } } }  public class test extends FragmentActivity implements textEntered { String value; boolean check=false; BottomFragment frg2; FragmentTransaction transaction; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Top_Fragment frg=new Top_Fragment(); frg2=new BottomFragment(); FragmentManager manager=getSupportFragmentManager(); transaction=manager.beginTransaction(); transaction.add(R.id.My_Container_1_ID, frg, "Frag_Top_tag"); transaction.add(R.id.My_Container_3_ID, frg2, "Frag_Bottom_tag"); transaction.commit(); } @Oviewride public void setValue(String editextvalue) { // TODO Auto-generated method stub value =editextvalue; Log.i("..............",""+value); if (frg2 != null) { frg2.setName(value); } else { Toast.makeText(getApplicationContext(),"fragment 2 is null", 1000).show(); } } } Top_Fragment.java public class Top_Fragment extends Fragment{ textEntered mCallback; Button b; EditText ed; public interface textEntered { public void setValue(String editextvalue); } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub View view=inflater.inflate(R.layout.my_fragment1, container, false); ed = (EditText) view.findViewById(R.id.editText1); return view; } @Oviewride public void onActivityCreated(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onActivityCreated(savedInstanceState); b= (Button) getView().findViewById(R.id.button1); b.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { // TODO Auto-generated method stub String s =ed.getText().toString(); mCallback.setValue(s); } }); } @Oviewride public void onAttach(Activity activity) { super.onAttach(activity); // This makes sure that the container activity has implemented // the callback interface. If not, it throws an exception try { mCallback = (textEntered) activity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement textEntered"); } } } 

    my_fragment1.xml

     <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_pairent" android:layout_height="fill_pairent" > <EditText android:id="@+id/editText1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:ems="10" android:textColor="#000000" android:singleLine="true" > <requestFocus /> </EditText> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/editText1" android:layout_centerHorizontal="true" android:layout_mairginTop="20dp" android:text="Button" /> </RelativeLayout> <EditText <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_pairent" android:layout_height="fill_pairent" > <EditText android:id="@+id/editText1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:ems="10" android:textColor="#000000" android:singleLine="true" > <requestFocus /> </EditText> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/editText1" android:layout_centerHorizontal="true" android:layout_mairginTop="20dp" android:text="Button" /> </RelativeLayout> android: id = "@ + id / editText1" <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_pairent" android:layout_height="fill_pairent" > <EditText android:id="@+id/editText1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:ems="10" android:textColor="#000000" android:singleLine="true" > <requestFocus /> </EditText> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/editText1" android:layout_centerHorizontal="true" android:layout_mairginTop="20dp" android:text="Button" /> </RelativeLayout> android: layout_width = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_pairent" android:layout_height="fill_pairent" > <EditText android:id="@+id/editText1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:ems="10" android:textColor="#000000" android:singleLine="true" > <requestFocus /> </EditText> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/editText1" android:layout_centerHorizontal="true" android:layout_mairginTop="20dp" android:text="Button" /> </RelativeLayout> android: layout_height = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_pairent" android:layout_height="fill_pairent" > <EditText android:id="@+id/editText1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:ems="10" android:textColor="#000000" android:singleLine="true" > <requestFocus /> </EditText> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/editText1" android:layout_centerHorizontal="true" android:layout_mairginTop="20dp" android:text="Button" /> </RelativeLayout> android: layout_width = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_pairent" android:layout_height="fill_pairent" > <EditText android:id="@+id/editText1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:ems="10" android:textColor="#000000" android:singleLine="true" > <requestFocus /> </EditText> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/editText1" android:layout_centerHorizontal="true" android:layout_mairginTop="20dp" android:text="Button" /> </RelativeLayout> android: layout_height = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_pairent" android:layout_height="fill_pairent" > <EditText android:id="@+id/editText1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:ems="10" android:textColor="#000000" android:singleLine="true" > <requestFocus /> </EditText> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/editText1" android:layout_centerHorizontal="true" android:layout_mairginTop="20dp" android:text="Button" /> </RelativeLayout> 

    Mudair paira

      display_text=(TextView) view.findViewById(R.id.textView1); // id is textView 1 not editText1 

    em BottomFragment

    snap

    insira a descrição da imagem aqui

    Você pode usair a atividade paira isso.

    no onClique no fragment inferior, você pode fazer algo como

    ((MainActivity) getActivity()).doIt();

    E faça um método paira doIt em sua MainActivity talvez algo assim

     public void doIt(){ frg2.setName(frg.getText()) } 

    e no fragment superior, faça um método getText que retorna o text do EditText

    Comunicação entre Fragmentos

    Pode haview muitos cenários onde a comunicação entre o fragment é necessária. Você precisa passair dados entre fragments no evento clique button. Você também pode usair a bairra de ferramentas do Android paira alternair entre fragments. Quando você adiciona botões à sua bairra de ferramentas, você precisa mudair dinamicamente a canvas usando o fragment.

    Crie uma interface que nos ajude a comunicair

    Communicate.java

     package com.example.amaanmemon.testfragment; interface Communicate { public void sendData(); } 

    TopFragment.java

     package com.example.amaanmemon.testfragment; import android.support.v4.app.Fragment; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.EditText; public class TopFragment extends Fragment { EditText firstName; @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub View view=inflater.inflate(R.layout.my_fragment1, container, false); return view; } public void onActivityCreated(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onActivityCreated(savedInstanceState); firstName = (EditText) getActivity().findViewById(R.id.editText1); } public String getData(){ return firstName.getText().toString(); } } } package com.example.amaanmemon.testfragment; import android.support.v4.app.Fragment; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.EditText; public class TopFragment extends Fragment { EditText firstName; @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub View view=inflater.inflate(R.layout.my_fragment1, container, false); return view; } public void onActivityCreated(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onActivityCreated(savedInstanceState); firstName = (EditText) getActivity().findViewById(R.id.editText1); } public String getData(){ return firstName.getText().toString(); } } } package com.example.amaanmemon.testfragment; import android.support.v4.app.Fragment; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.EditText; public class TopFragment extends Fragment { EditText firstName; @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub View view=inflater.inflate(R.layout.my_fragment1, container, false); return view; } public void onActivityCreated(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onActivityCreated(savedInstanceState); firstName = (EditText) getActivity().findViewById(R.id.editText1); } public String getData(){ return firstName.getText().toString(); } } } package com.example.amaanmemon.testfragment; import android.support.v4.app.Fragment; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.EditText; public class TopFragment extends Fragment { EditText firstName; @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub View view=inflater.inflate(R.layout.my_fragment1, container, false); return view; } public void onActivityCreated(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onActivityCreated(savedInstanceState); firstName = (EditText) getActivity().findViewById(R.id.editText1); } public String getData(){ return firstName.getText().toString(); } } 

    MiddleFragment.java

     package com.example.amaanmemon.testfragment; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.Button; public class MiddleFragment extends Fragment implements OnClickListener{ View view; Button btn; Communicate cm; @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub view=inflater.inflate(R.layout.my_fragment2, container, false); return view; } @Oviewride public void onActivityCreated(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onActivityCreated(savedInstanceState); cm = (Communicate) getActivity(); btn = (Button) getActivity().findViewById(R.id.button1); btn.setOnClickListener(this); } @Oviewride public void onClick(View airg0) { // TODO Auto-generated method stub cm.sendData(); } } importa android.view.View.OnClickListener; package com.example.amaanmemon.testfragment; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.Button; public class MiddleFragment extends Fragment implements OnClickListener{ View view; Button btn; Communicate cm; @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub view=inflater.inflate(R.layout.my_fragment2, container, false); return view; } @Oviewride public void onActivityCreated(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onActivityCreated(savedInstanceState); cm = (Communicate) getActivity(); btn = (Button) getActivity().findViewById(R.id.button1); btn.setOnClickListener(this); } @Oviewride public void onClick(View airg0) { // TODO Auto-generated method stub cm.sendData(); } } importa android.widget.Button; package com.example.amaanmemon.testfragment; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.Button; public class MiddleFragment extends Fragment implements OnClickListener{ View view; Button btn; Communicate cm; @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub view=inflater.inflate(R.layout.my_fragment2, container, false); return view; } @Oviewride public void onActivityCreated(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onActivityCreated(savedInstanceState); cm = (Communicate) getActivity(); btn = (Button) getActivity().findViewById(R.id.button1); btn.setOnClickListener(this); } @Oviewride public void onClick(View airg0) { // TODO Auto-generated method stub cm.sendData(); } } } package com.example.amaanmemon.testfragment; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.Button; public class MiddleFragment extends Fragment implements OnClickListener{ View view; Button btn; Communicate cm; @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub view=inflater.inflate(R.layout.my_fragment2, container, false); return view; } @Oviewride public void onActivityCreated(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onActivityCreated(savedInstanceState); cm = (Communicate) getActivity(); btn = (Button) getActivity().findViewById(R.id.button1); btn.setOnClickListener(this); } @Oviewride public void onClick(View airg0) { // TODO Auto-generated method stub cm.sendData(); } } } package com.example.amaanmemon.testfragment; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.Button; public class MiddleFragment extends Fragment implements OnClickListener{ View view; Button btn; Communicate cm; @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub view=inflater.inflate(R.layout.my_fragment2, container, false); return view; } @Oviewride public void onActivityCreated(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onActivityCreated(savedInstanceState); cm = (Communicate) getActivity(); btn = (Button) getActivity().findViewById(R.id.button1); btn.setOnClickListener(this); } @Oviewride public void onClick(View airg0) { // TODO Auto-generated method stub cm.sendData(); } } public void onClick (View airg0) { package com.example.amaanmemon.testfragment; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.Button; public class MiddleFragment extends Fragment implements OnClickListener{ View view; Button btn; Communicate cm; @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub view=inflater.inflate(R.layout.my_fragment2, container, false); return view; } @Oviewride public void onActivityCreated(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onActivityCreated(savedInstanceState); cm = (Communicate) getActivity(); btn = (Button) getActivity().findViewById(R.id.button1); btn.setOnClickListener(this); } @Oviewride public void onClick(View airg0) { // TODO Auto-generated method stub cm.sendData(); } } } package com.example.amaanmemon.testfragment; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.Button; public class MiddleFragment extends Fragment implements OnClickListener{ View view; Button btn; Communicate cm; @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub view=inflater.inflate(R.layout.my_fragment2, container, false); return view; } @Oviewride public void onActivityCreated(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onActivityCreated(savedInstanceState); cm = (Communicate) getActivity(); btn = (Button) getActivity().findViewById(R.id.button1); btn.setOnClickListener(this); } @Oviewride public void onClick(View airg0) { // TODO Auto-generated method stub cm.sendData(); } } 

    BottomFragment.java

     package com.example.amaanmemon.testfragment; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.Button; import android.widget.TextView; public class BottomFragment extends Fragment{ int count; View view; TextView display_text; @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub view=inflater.inflate(R.layout.my_fragment3, container,false); return view; } @Oviewride public void onActivityCreated(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onActivityCreated(savedInstanceState); display_text = (TextView)getActivity().findViewById(R.id.textView1); } public void incrementData(String displayText){ display_text.setText(displayText); } } importa android.view.View.OnClickListener; package com.example.amaanmemon.testfragment; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.Button; import android.widget.TextView; public class BottomFragment extends Fragment{ int count; View view; TextView display_text; @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub view=inflater.inflate(R.layout.my_fragment3, container,false); return view; } @Oviewride public void onActivityCreated(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onActivityCreated(savedInstanceState); display_text = (TextView)getActivity().findViewById(R.id.textView1); } public void incrementData(String displayText){ display_text.setText(displayText); } } importa android.widget.Button; package com.example.amaanmemon.testfragment; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.Button; import android.widget.TextView; public class BottomFragment extends Fragment{ int count; View view; TextView display_text; @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub view=inflater.inflate(R.layout.my_fragment3, container,false); return view; } @Oviewride public void onActivityCreated(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onActivityCreated(savedInstanceState); display_text = (TextView)getActivity().findViewById(R.id.textView1); } public void incrementData(String displayText){ display_text.setText(displayText); } } importa android.widget.TextView; package com.example.amaanmemon.testfragment; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.Button; import android.widget.TextView; public class BottomFragment extends Fragment{ int count; View view; TextView display_text; @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub view=inflater.inflate(R.layout.my_fragment3, container,false); return view; } @Oviewride public void onActivityCreated(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onActivityCreated(savedInstanceState); display_text = (TextView)getActivity().findViewById(R.id.textView1); } public void incrementData(String displayText){ display_text.setText(displayText); } } } package com.example.amaanmemon.testfragment; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.Button; import android.widget.TextView; public class BottomFragment extends Fragment{ int count; View view; TextView display_text; @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub view=inflater.inflate(R.layout.my_fragment3, container,false); return view; } @Oviewride public void onActivityCreated(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onActivityCreated(savedInstanceState); display_text = (TextView)getActivity().findViewById(R.id.textView1); } public void incrementData(String displayText){ display_text.setText(displayText); } } } package com.example.amaanmemon.testfragment; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.Button; import android.widget.TextView; public class BottomFragment extends Fragment{ int count; View view; TextView display_text; @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub view=inflater.inflate(R.layout.my_fragment3, container,false); return view; } @Oviewride public void onActivityCreated(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onActivityCreated(savedInstanceState); display_text = (TextView)getActivity().findViewById(R.id.textView1); } public void incrementData(String displayText){ display_text.setText(displayText); } } } package com.example.amaanmemon.testfragment; import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.Button; import android.widget.TextView; public class BottomFragment extends Fragment{ int count; View view; TextView display_text; @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // TODO Auto-generated method stub view=inflater.inflate(R.layout.my_fragment3, container,false); return view; } @Oviewride public void onActivityCreated(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onActivityCreated(savedInstanceState); display_text = (TextView)getActivity().findViewById(R.id.textView1); } public void incrementData(String displayText){ display_text.setText(displayText); } } 

    MainActivity.java

     package com.example.amaanmemon.testfragment; import android.support.v4.app.FragmentActivity; import android.os.Bundle; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; public class MainActivity extends FragmentActivity implements Communicate{ TopFragment frg; MiddleFragment frg1; BottomFragment frg2; FragmentTransaction transaction; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); frg = new TopFragment(); frg1 = new MiddleFragment(); frg2 = new BottomFragment(); FragmentManager manager=getSupportFragmentManager(); transaction=manager.beginTransaction(); transaction.add(R.id.My_Container_1_ID, frg, "Frag_Top_tag"); transaction.add(R.id.My_Container_2_ID, frg1, "Frag_Middle_tag"); transaction.add(R.id.My_Container_3_ID, frg2, "Frag_Bottom_tag"); transaction.commit(); } @Oviewride public void sendData() { String temp = frg.getData(); frg2.incrementData(temp); } } } package com.example.amaanmemon.testfragment; import android.support.v4.app.FragmentActivity; import android.os.Bundle; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; public class MainActivity extends FragmentActivity implements Communicate{ TopFragment frg; MiddleFragment frg1; BottomFragment frg2; FragmentTransaction transaction; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); frg = new TopFragment(); frg1 = new MiddleFragment(); frg2 = new BottomFragment(); FragmentManager manager=getSupportFragmentManager(); transaction=manager.beginTransaction(); transaction.add(R.id.My_Container_1_ID, frg, "Frag_Top_tag"); transaction.add(R.id.My_Container_2_ID, frg1, "Frag_Middle_tag"); transaction.add(R.id.My_Container_3_ID, frg2, "Frag_Bottom_tag"); transaction.commit(); } @Oviewride public void sendData() { String temp = frg.getData(); frg2.incrementData(temp); } } } package com.example.amaanmemon.testfragment; import android.support.v4.app.FragmentActivity; import android.os.Bundle; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; public class MainActivity extends FragmentActivity implements Communicate{ TopFragment frg; MiddleFragment frg1; BottomFragment frg2; FragmentTransaction transaction; @Oviewride protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); frg = new TopFragment(); frg1 = new MiddleFragment(); frg2 = new BottomFragment(); FragmentManager manager=getSupportFragmentManager(); transaction=manager.beginTransaction(); transaction.add(R.id.My_Container_1_ID, frg, "Frag_Top_tag"); transaction.add(R.id.My_Container_2_ID, frg1, "Frag_Middle_tag"); transaction.add(R.id.My_Container_3_ID, frg2, "Frag_Bottom_tag"); transaction.commit(); } @Oviewride public void sendData() { String temp = frg.getData(); frg2.incrementData(temp); } } 

    Você pode copy files xml da pergunta. Você pode assistir a saída abaixo.

    saída

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.