title: Reference to elements of fragment from activity
body: <p>It is possible to get reference to element(like button) defined in xml layout of fragment and use it in another activity?</p>
  
  <p>I tried to do that but have null object reference.</p>
  
  <p>fragment_date_picker.xml</p>
  
  <pre><code>&lt;TimePicker
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:id="@+id/timePicker"
      android:layout_gravity="center_horizontal|top" /&gt;
  
  &lt;Button
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="ok"
      android:id="@+id/bt_ok"
      android:layout_gravity="center" /&gt;
  </code></pre>
  
  <p>MainActivity.java</p>
  
  <pre><code>btPickTime=(Button)findViewById(R.id.bt_pickTime);
      AlarmManager alarmManager=(AlarmManager)getSystemService(ALARM_SERVICE);
      final DatePickerFragment dp=new DatePickerFragment();
  
      btOk=(Button)findViewById(R.id.bt_ok);
      btOk.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              FragmentManager fm = getFragmentManager();
              FragmentTransaction ft = fm.beginTransaction();
              ft.remove(dp);
              ft.commit();
          }
      });
      btPickTime.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
  
              FragmentManager fm = getFragmentManager();
              FragmentTransaction ft = fm.beginTransaction();
              ft.add(R.id.ll_main
                      ,dp);
              ft.commit();
  
          }
      });
  </code></pre>