title: dynamic communication between fragments Fail
body: <p>I am trying to communicate dynamically between two <code>fragments</code>. <code>Frag1</code> imlements <code>sensorlistener</code> and passes the values to the <code>mainActivity</code>.</p>
  
  <p>the <code>mainActivity</code> implements <code>onSendListener.onSendValues</code> interface. in the implementation of <code>onSendValues</code> in the <code>mainActivity</code>, when the user clicks the button defined in <code>Frag1</code>, I pass the values of the Accelerometer (x,y,z) received from <code>Frag1</code> to the <code>Frag2</code> through the <code>mainActivity</code>by accessing <code>Frag2</code>'s public methods </p>
  
  <pre><code>void returnedX(float x) {...}
  void returnedY(float y) {...}
  void returnedZ(float z) {...}
  </code></pre>
  
  <p>what happens is, when the user clicks the button in <code>Frag1</code>, the <code>textViews</code> in <code>Frag2</code> displays nothing despite their public methods </p>
  
  <pre><code>void returnedX(float x) {...}
  void returnedY(float y) {...}
  void returnedZ(float z) {...}
  </code></pre>
  
  <p>are called, i am sure they were called because as shown below in the code, the <code>Log</code> statements in the public methods in <code>Frag2</code> is displayed but the values of the acceöerometer not. </p>
  
  <p>please see below the code, and let me know why the public methods in <code>Frag2</code> do not display the passed date from <code>Frag1</code></p>
  
  <p><strong>MainActivity</strong>:</p>
  
  <pre><code>public class MainActivity extends Activity implements onSendListener {
  
  Frag2 frag2;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main_activity);
  
      frag2 = (Frag2)getFragmentManager().findFragmentById (R.id.frag_2);
  }
  
  /**
   * to send values from frag1 to frag2 through mainActivity. use bundle.
   */
  @Override
  public void onSendValues(float x, float y, float z) {
      // TODO Auto-generated method stub      
      frag2.returnedX(x);
      frag2.returnedY(y);
      frag2.returnedZ(z);
  }
  </code></pre>
  
  <p>}</p>
  
  <p><strong>Frag1</strong>:</p>
  
  <pre><code>public class Frag1 extends Fragment implements SensorEventListener {
  
  private SensorManager sensorManager;
  TextView tvAccX;
  TextView tvAccY;
  TextView tvAccZ;
  
  private float x = 0.0f;
  private float y = 0.0f;
  private float z = 0.0f;
  
  private void setAccX(float x) {
      this.x = x;
  }
  private float getAccX() {
      return this.x;
  }
  
  private void setAccY(float y) {
      this.y = y;
  }
  private float getAccY() {
      return this.y;
  }
  
  private void setAccZ(float z) {
      this.z = z;
  }
  private float getAccZ() {
      return this.z;
  }
  
  Button btnSend;
  onSendListener sendValues;
  
  @Override
  public void onAttach(Activity activity) {
      // TODO Auto-generated method stub
      super.onAttach(activity);
  
      sendValues = (onSendListener) activity;
      sensorManager = (SensorManager) getActivity().getSystemService(Context.SENSOR_SERVICE);
  }
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
          Bundle savedInstanceState) {
      // TODO Auto-generated method stub
      View view = inflater.inflate(R.layout.frag_1, container, false);
  
      tvAccX = (TextView) view.findViewById(R.id.tv_accX_value);
      tvAccY = (TextView) view.findViewById(R.id.tv_accY_value);
      tvAccZ = (TextView) view.findViewById(R.id.tv_accZ_value);
      btnSend = (Button) view.findViewById(R.id.btn_send);
  
      return view;
  }
  
  @Override
  public void onSensorChanged(SensorEvent event) {
      // TODO Auto-generated method stub
      switch (event.sensor.getType()) {
      case Sensor.TYPE_ACCELEROMETER:
          showAccReadings(event);
          break;
  
      default:
          break;
      }
  }
  
  @Override
  public void onAccuracyChanged(Sensor sensor, int accuracy) {
      // TODO Auto-generated method stub
  
  }
  
  private void showAccReadings(SensorEvent event) {
      // TODO Auto-generated method stub
      float[] values = event.values;
  
      float x = values[0];
      float y = values[1];
      float z = values[2];
  
      setAccX(x);
      setAccY(y);
      setAccZ(z);
  
      tvAccX.setText(String.valueOf(x));
      tvAccY.setText(String.valueOf(y));
      tvAccZ.setText(String.valueOf(z));
  }
  
  @Override
  public void onResume() {
      // TODO Auto-generated method stub
      super.onResume();
  
      Sensor accSensor = sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
      sensorManager.registerListener(this, accSensor, sensorManager.SENSOR_DELAY_FASTEST);
  
      btnSend.setOnClickListener(new OnClickListener() {
  
          @Override
          public void onClick(View v) {
              // TODO Auto-generated method stub
              sendValues.onSendValues(getAccX(), getAccY(), getAccZ());
          }
      });
  }
  
  @Override
  public void onPause() {
      // TODO Auto-generated method stub
      super.onPause();
      sensorManager.unregisterListener(this);
  }
  </code></pre>
  
  <p>}</p>
  
  <p><strong>Frag2</strong>:</p>
  
  <pre><code>public class Frag2 extends Fragment {
  
  TextView tvX;
  TextView tvY;
  TextView tvZ;
  
  float returnX ;
  float returnY ;
  float returnZ ;
  
  void returnedX(float x) {
      if (getView() != null) {
          Log.d("Frag2", "X: View is not null");
          this.returnX = x;
      }
  }
  void returnedY(float y) {
      if (getView() != null) {
          Log.d("Frag2", "Y: View is not null");
          this.returnY = y;
      }
  }
  void returnedZ(float z) {
      if (getView() != null) {
          Log.d("Frag2", "Z: View is not null");
          this.returnZ = z;
      }
  }
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
      // TODO Auto-generated method stub
  
      View view = inflater.inflate(R.layout.frag_2, container, false);
  
      tvX = (TextView) view.findViewById(R.id.tv_accX2_label);
      tvY = (TextView) view.findViewById(R.id.tv_accY2_label);
      tvZ = (TextView) view.findViewById(R.id.tv_accZ2_label);
  
      return view;
  }
  
  @Override
  public void onViewCreated(View view, Bundle savedInstanceState) {
      // TODO Auto-generated method stub
      super.onViewCreated(view, savedInstanceState);
  
      Log.d("Frag2", "View is not null");
      tvX.setText("" + this.returnX);
      tvY.setText("" + this.returnY);
      tvZ.setText("" + this.returnZ);
  }
  </code></pre>
  
  <p>}</p>
  
  <p><strong>Log Output</strong>:</p>
  
  <pre><code>01-26 13:03:36.876: D/Frag2(16146): X: View is not null
  01-26 13:03:36.876: D/Frag2(16146): Y: View is not null
  01-26 13:03:36.876: D/Frag2(16146): Z: View is not null
  </code></pre>