Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class DatePicker extends DialogFragment
- implements DatePickerDialog.OnDateSetListener {
- int year;
- int month;
- int day;
- @Override
- public Dialog onCreateDialog(Bundle savedInstanceState) {
- // определяем текущую дату
- 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);
- // создаем DatePickerDialog и возвращаем его
- Dialog picker = new DatePickerDialog(getActivity(), this,
- year, month, day);
- //picker.setTitle(getResources().getString(R.string.choose_date));
- return picker;
- }
- @Override
- public void onStart() {
- super.onStart();
- // добавляем кастомный текст для кнопки
- Button nButton = ((AlertDialog) getDialog())
- .getButton(DialogInterface.BUTTON_POSITIVE);
- nButton.setText(getResources().getString(R.string.Ok));
- }
- @Override
- public void onDateSet(android.widget.DatePicker datePicker, int year,
- int month, int day) {
- //TextView tv = (TextView) getActivity().findViewById(R.id.tv);
- //tv.setText(day + "-" + month + "-" + year);
- Button btDate = (Button) getActivity().findViewById(R.id.btDate);
- btDate.setText(day + "-" + month + "-" + year);
- }
- public void onCl_btDate(View view) {
- DialogFragment dateDialog = new DatePicker();
- dateDialog.show(getSupportFragmentManager(), "datePicker");
- }
Add Comment
Please, Sign In to add comment