Advertisement
Guest User

DatePickerFragment

a guest
Apr 25th, 2018
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. package example.uuj.employeerecords;
  2.  
  3. import android.app.DatePickerDialog;
  4. import android.app.Dialog;
  5. import android.app.DialogFragment;
  6. import android.os.Bundle;
  7. import android.widget.DatePicker;
  8. import android.widget.TextView;
  9.  
  10. import java.util.Calendar;
  11.  
  12. public class DatePickerFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener
  13. {
  14.  
  15. @Override
  16. public Dialog onCreateDialog(Bundle savedInstanceState)
  17. {
  18. // Use the current date to get the default date
  19. final Calendar c = Calendar.getInstance();
  20. int year = c.get(Calendar.YEAR);
  21. int month = c.get(Calendar.MONTH);
  22. int day = c.get(Calendar.DAY_OF_MONTH);
  23.  
  24. // Create and return a new instance of DatePickerDialog
  25. return new DatePickerDialog(getActivity(), this, year, month, day);
  26. }
  27. // onDateSet() method to display date in textview
  28. public void onDateSet(DatePicker view, int year, int month, int day)
  29. {
  30. TextView tv = (TextView) getActivity().findViewById( R.id.txtdisplaydate);
  31. tv.setText(tv.getText()+ String.valueOf(day) + " / " + String.valueOf(month) + " / " + String.valueOf(year)+ "\n");
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement