title: Date from datepicker dialog not getting set in textview of the popup android
body: <p>My question is in onDateSet method, how do i retrieve the selected date from the datepicker dialog on my textview field which is an activity embedded on popup. I get the nullpointer exception for:
    ((TextView) getActivity().findViewById(R.id.spinner_date)).setText("Date"+year);</p>
  
  <p><strong>DatePickerFragment.java</strong></p>
  
  <pre><code>public class DatePickerFragment extends DialogFragment
      implements DatePickerDialog.OnDateSetListener {
  
  @Override
  public Dialog onCreateDialog(Bundle savedInstanceState) {
      // Use the current date as the default date in the picker
      final Calendar c = Calendar.getInstance();
      int year = c.get(Calendar.YEAR);
      int month = c.get(Calendar.MONTH);
      int day = c.get(Calendar.DAY_OF_MONTH);
  
      // Create a new instance of DatePickerDialog and return it
      return new DatePickerDialog(getActivity(), this, year, month, day);
  }
  
  
  public void onDateSet(DatePicker view, int year, int month, int day) {
       Log.w("DatePicker", "Date = " + year);
    ((TextView) getActivity().findViewById(R.id.spinner_date)).setText("Date"+year);
  }
  </code></pre>
  
  <p>}</p>
  
  <p><strong>In MainActivity.java</strong></p>
  
  <pre><code>     public void createVideoEvent(View arg0) {
      LayoutInflater layoutInflater
              = (LayoutInflater) getBaseContext()
              .getSystemService(LAYOUT_INFLATER_SERVICE);
      popupView = layoutInflater.inflate(R.layout.activity_event_create,          null);
      final PopupWindow popupWindow = new PopupWindow(
              popupView,
             400,
              LayoutParams.WRAP_CONTENT);
      View new_event_button = (View) findViewById(R.id.button);
      popupWindow.showAsDropDown(new_event_button);
  
     dateSpinner = (TextView) popupView.findViewById(R.id.spinner_date);
  
      View.OnTouchListener Spinner_OnTouch = new View.OnTouchListener() {
          public boolean onTouch(View v, MotionEvent event) {
              if (event.getAction() == MotionEvent.ACTION_UP) {
                  showDatePickerDialog(v);
              }
              return true;
          }
      };
      View.OnKeyListener Spinner_OnKey = new View.OnKeyListener() {
          public boolean onKey(View v, int keyCode, KeyEvent event) {
              if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
                  showDatePickerDialog(v);
                  return true;
              } else {
                  return false;
              }
          }
      };
  
      dateSpinner.setOnTouchListener(Spinner_OnTouch);
      dateSpinner.setOnKeyListener(Spinner_OnKey);
       SimpleDateFormat sdf = new SimpleDateFormat("cccc, MMMM dd, yyyy", Locale.US);
      dateSpinner.setText(sdf.format(myCalendar.getTime()));
  
  }
  public void showDatePickerDialog(View v) {
      DialogFragment newFragment = new DatePickerFragment();
      newFragment.show(getFragmentManager(), "Date");
  
  }
  </code></pre>