El diálogo Datepicker no coincide con la fecha seleccionada
Consulte la siguiente imagen:
- Establecer fecha y hora seleccionador de fecha y hora en android
- Uso del Kit Kat DatePicker en el dispositivo Lolipop
- Android - OnDateChangedListener - ¿cómo se establece esto?
- Cómo evitar la fecha seleccionada pasada en DatePickerDialog (setMinDate no funciona como se esperaba)
- Datepicker con estilo diferente a la actividad
El texto arriba dice Thu, Oct 28, 1909 … mientras que el datepicker realmente tiene el valor 3 de enero de 1902. ¿Cuál es el error?
Aquí está mi código:
@SuppressWarnings("deprecation") public void setTheDate(View v){ showDialog(DATE_DIALOG_ID); } @Override protected Dialog onCreateDialog(int id) { switch (id) { case DATE_DIALOG_ID: // set date picker as current date return new DatePickerDialog(this, datePickerListener, year, month,day); } return null; } private DatePickerDialog.OnDateSetListener datePickerListener = new DatePickerDialog.OnDateSetListener() { // when dialog box is closed, below method will be called. public void onDateSet(DatePicker view, int selectedYear, int selectedMonth, int selectedDay) { year = selectedYear; month = selectedMonth; day = selectedDay; System.out.println("date" + year + month + day); } };
DATE_DIALOG_ID es una constante final, y llamo el método setTheDate () al hacer clic en un botón.
¿Qué estoy haciendo mal?
- Validar "desde fecha" y "hasta la fecha" en android
- Calender.getInstance () da error en Android Studio
- Datepicker da tiempo no entre excepciones
- Fecha máxima en un DatePickerDialog de Android
- ¿Cómo conservar el estado del diálogo de fecha y hora en el cambio de orientación?
- Cómo establecer DatePickerDialog valor a EditText?
- Cambiar los textos de los botones de DatePickerDialog
- Test DatePickerDialog con robolectric
Simplemente intente esto, similar a su código solamente, pero está funcionando para mí.
Calendar c = Calendar.getInstance(); mYear = c.get(Calendar.YEAR); mMonth = c.get(Calendar.MONTH); mDay = c.get(Calendar.DAY_OF_MONTH); y = c.get(Calendar.YEAR); m = c.get(Calendar.MONTH); dy = c.get(Calendar.DAY_OF_MONTH); DatePickerDialog.OnDateSetListener mDateSetListener = new DatePickerDialog.OnDateSetListener() { public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { Log.d("err", "onselect"); mYear = year; mMonth = monthOfYear; mDay = dayOfMonth; } }; DatePickerDialog d = new DatePickerDialog(getActivity(), mDateSetListener, mYear, mMonth, mDay); d.show();
Puede utilizar este código para recuperar el valor del selector de fechas. Agregue este código dentro del onDateSet() method of OnDateSetListener()
TimestampField field = (TimestampField) fieldpicker; Timestamp timestamp = field.getTimestamp(); timestamp.setYear(year - 1900); timestamp.setMonth(monthOfYear); timestamp.setDate(dayOfMonth); field.setTimestamp(timestamp);
Esto mostrará la fecha en el formato correcto
- Más Eclipse ADT Insanity! Logcat se ha desconectado completamente
- Gráfico de barras multicolor con desplazamiento