Guest User

Untitled

a guest
Oct 19th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. public class DatePicker extends DialogFragment
  2. implements DatePickerDialog.OnDateSetListener {
  3. int year;
  4. int month;
  5. int day;
  6. @Override
  7. public Dialog onCreateDialog(Bundle savedInstanceState) {
  8.  
  9. // определяем текущую дату
  10. final Calendar c = Calendar.getInstance();
  11. int year = c.get(Calendar.YEAR);
  12. int month = c.get(Calendar.MONTH);
  13. int day = c.get(Calendar.DAY_OF_MONTH);
  14.  
  15. // создаем DatePickerDialog и возвращаем его
  16. Dialog picker = new DatePickerDialog(getActivity(), this,
  17. year, month, day);
  18. //picker.setTitle(getResources().getString(R.string.choose_date));
  19.  
  20. return picker;
  21. }
  22. @Override
  23. public void onStart() {
  24. super.onStart();
  25. // добавляем кастомный текст для кнопки
  26. Button nButton = ((AlertDialog) getDialog())
  27. .getButton(DialogInterface.BUTTON_POSITIVE);
  28. nButton.setText(getResources().getString(R.string.Ok));
  29. }
  30.  
  31. @Override
  32. public void onDateSet(android.widget.DatePicker datePicker, int year,
  33. int month, int day) {
  34. //TextView tv = (TextView) getActivity().findViewById(R.id.tv);
  35. //tv.setText(day + "-" + month + "-" + year);
  36. Button btDate = (Button) getActivity().findViewById(R.id.btDate);
  37. btDate.setText(day + "-" + month + "-" + year);
  38.  
  39. }
  40.  
  41. public void onCl_btDate(View view) {
  42. DialogFragment dateDialog = new DatePicker();
  43. dateDialog.show(getSupportFragmentManager(), "datePicker");
  44. }
Add Comment
Please, Sign In to add comment