title: Android DatePicker won't set date in textview on the first try
body: <p>I'm trying to set date in the textview from a fragment. The problem is that, after picking a date and clicking the ok button of the dialog, it won't instantly set the date to the textview. Upon clicking the set date button again, that's when the date gets set in the textview.</p>
  
  <p>ButtonFragment</p>
  
  <pre><code>public class ButtonFragment extends Fragment {
  
  Button date;
  TextView datetext;
  Date dateInterface;
  
  @Nullable
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      View view = inflater.inflate(R.layout.button_fragment, container, false);
      date = (Button) view.findViewById(R.id.date);
      datetext = (TextView) view.findViewById(R.id.datetext);
      date.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              dateInterface.setDate(datetext);
          }
      });
      datetext = (TextView) view.findViewById(R.id.datetext);
      return view;
  }
  
  @Override
  public void onAttach(Activity activity) {
      super.onAttach(activity);
      try{
          dateInterface = (Date) activity;
      }catch(Exception e) {
  
      }
  }
  
  public interface Date{
  
      public void setDate(TextView textView);
  
   }
  }
  </code></pre>
  
  <p>MainActivity</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity implements ButtonFragment.Date {
  
  Calendar c = Calendar.getInstance();
  TextView display;
  int cday, cmonth, cyear;
  String date;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      FragmentManager fragmentManager = getFragmentManager();
      FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
      ButtonFragment buttonFragment = new ButtonFragment();
      fragmentTransaction.add(R.id.fragment_container, buttonFragment);
      fragmentTransaction.commit();
  }
  
  public void setDate(String date) {
      this.date = date;
  }
  
  public String getDate() {
      return this.date;
  }
  
  DatePickerDialog.OnDateSetListener d = new OnDateSetListener() {
  
      @Override
      public void onDateSet(DatePicker view, int year, int monthOfYear,
                            int dayOfMonth) {
  
          cday = dayOfMonth;
          cmonth = monthOfYear + 1;
          cyear = year;
  
      }
  };
  
  @Override
  public void setDate(TextView textView) {
      new DatePickerDialog(MainActivity.this, d,
              c.get(Calendar.YEAR), c.get(Calendar.MONTH), c
              .get(Calendar.DAY_OF_MONTH)).show();
  
  
      date = "Choosen date is :" + cday + "/" + cmonth + "/"
              + cyear;
  
      textView.setText(date);
   }
  }
  </code></pre>