Calendar Object seams not to be handed to the method using Android and datepicker [duplicate]
This question already has an answer here:
Java Calendar always shows the same time
5 answers
Can't add days to Calendar
1 answer
I have a silly beginner question.
I am using the Andriod datepicker to do some data entry. Overall I want to store and retrieve data from a firestore db.
But currently I am struggling with with Calendar and datepicker. The last method (updateDatepickerFromCalendar) is used to update the datapicker with the new data once retrieved. You will not find that one ... but I added a tempory Calendar object which also fails.
The other way around to update the Calendar object from the date picker works perfekt. But if I want to update the date picker from the Calendar object it seams that the calendar object is not handed to the method updateDatepickerFromCalendar while the datepicker object is.
Any Idea what I am doing wrong?
// retrieve data
ladeknopf.setOnClickListener( (View v) ->
eingabename.setText(datensatz.getNameDerPerson());
Calendar testDatum; // just for testing
testDatum = Calendar.getInstance();
testDatum.set(1999,11,2);
updateDatepickerFromCalendar(testDatum, eingabedatum);
eingabeueberbblick.setText(datensatz.valuesToString());
);
}
// Datepicker Hilfsmethoden
// calendar object mit Daten aus Datepicker
private void updateCalendarFromDatepicker(Calendar cal3, DatePicker dp)
cal3.set(Calendar.YEAR, dp.getYear());
cal3.set(Calendar.MONTH, dp.getMonth());
cal3.set(Calendar.DAY_OF_MONTH, dp.getDayOfMonth());
// here is the issue: pb is handed over but the Calendar Object not
private void updateDatepickerFromCalendar(Calendar cal2, DatePicker dp)
dp.updateDate(cal2.YEAR, cal2.MONTH, cal2.DAY_OF_MONTH);
Thank you in advance.
java android calendar
marked as duplicate by Ole V.V.
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Nov 12 at 7:40
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Java Calendar always shows the same time
5 answers
Can't add days to Calendar
1 answer
I have a silly beginner question.
I am using the Andriod datepicker to do some data entry. Overall I want to store and retrieve data from a firestore db.
But currently I am struggling with with Calendar and datepicker. The last method (updateDatepickerFromCalendar) is used to update the datapicker with the new data once retrieved. You will not find that one ... but I added a tempory Calendar object which also fails.
The other way around to update the Calendar object from the date picker works perfekt. But if I want to update the date picker from the Calendar object it seams that the calendar object is not handed to the method updateDatepickerFromCalendar while the datepicker object is.
Any Idea what I am doing wrong?
// retrieve data
ladeknopf.setOnClickListener( (View v) ->
eingabename.setText(datensatz.getNameDerPerson());
Calendar testDatum; // just for testing
testDatum = Calendar.getInstance();
testDatum.set(1999,11,2);
updateDatepickerFromCalendar(testDatum, eingabedatum);
eingabeueberbblick.setText(datensatz.valuesToString());
);
}
// Datepicker Hilfsmethoden
// calendar object mit Daten aus Datepicker
private void updateCalendarFromDatepicker(Calendar cal3, DatePicker dp)
cal3.set(Calendar.YEAR, dp.getYear());
cal3.set(Calendar.MONTH, dp.getMonth());
cal3.set(Calendar.DAY_OF_MONTH, dp.getDayOfMonth());
// here is the issue: pb is handed over but the Calendar Object not
private void updateDatepickerFromCalendar(Calendar cal2, DatePicker dp)
dp.updateDate(cal2.YEAR, cal2.MONTH, cal2.DAY_OF_MONTH);
Thank you in advance.
java android calendar
marked as duplicate by Ole V.V.
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Nov 12 at 7:40
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
Can you usejava.time
, the modern Java date and time API, with your Android version? Not that it will solve your issue (likely), but it’s much nicer to work with. TheCalendar
class has some design issues and is long outdated.
– Ole V.V.
Nov 11 at 9:59
Changed my mind, using java.time will solve your issue. An error like usingcal2.YEAR
instead ofcal2.get(Calendar.YEAR)
simply isn’t possible with java.time due to its superior design.
– Ole V.V.
Nov 12 at 7:43
add a comment |
This question already has an answer here:
Java Calendar always shows the same time
5 answers
Can't add days to Calendar
1 answer
I have a silly beginner question.
I am using the Andriod datepicker to do some data entry. Overall I want to store and retrieve data from a firestore db.
But currently I am struggling with with Calendar and datepicker. The last method (updateDatepickerFromCalendar) is used to update the datapicker with the new data once retrieved. You will not find that one ... but I added a tempory Calendar object which also fails.
The other way around to update the Calendar object from the date picker works perfekt. But if I want to update the date picker from the Calendar object it seams that the calendar object is not handed to the method updateDatepickerFromCalendar while the datepicker object is.
Any Idea what I am doing wrong?
// retrieve data
ladeknopf.setOnClickListener( (View v) ->
eingabename.setText(datensatz.getNameDerPerson());
Calendar testDatum; // just for testing
testDatum = Calendar.getInstance();
testDatum.set(1999,11,2);
updateDatepickerFromCalendar(testDatum, eingabedatum);
eingabeueberbblick.setText(datensatz.valuesToString());
);
}
// Datepicker Hilfsmethoden
// calendar object mit Daten aus Datepicker
private void updateCalendarFromDatepicker(Calendar cal3, DatePicker dp)
cal3.set(Calendar.YEAR, dp.getYear());
cal3.set(Calendar.MONTH, dp.getMonth());
cal3.set(Calendar.DAY_OF_MONTH, dp.getDayOfMonth());
// here is the issue: pb is handed over but the Calendar Object not
private void updateDatepickerFromCalendar(Calendar cal2, DatePicker dp)
dp.updateDate(cal2.YEAR, cal2.MONTH, cal2.DAY_OF_MONTH);
Thank you in advance.
java android calendar
This question already has an answer here:
Java Calendar always shows the same time
5 answers
Can't add days to Calendar
1 answer
I have a silly beginner question.
I am using the Andriod datepicker to do some data entry. Overall I want to store and retrieve data from a firestore db.
But currently I am struggling with with Calendar and datepicker. The last method (updateDatepickerFromCalendar) is used to update the datapicker with the new data once retrieved. You will not find that one ... but I added a tempory Calendar object which also fails.
The other way around to update the Calendar object from the date picker works perfekt. But if I want to update the date picker from the Calendar object it seams that the calendar object is not handed to the method updateDatepickerFromCalendar while the datepicker object is.
Any Idea what I am doing wrong?
// retrieve data
ladeknopf.setOnClickListener( (View v) ->
eingabename.setText(datensatz.getNameDerPerson());
Calendar testDatum; // just for testing
testDatum = Calendar.getInstance();
testDatum.set(1999,11,2);
updateDatepickerFromCalendar(testDatum, eingabedatum);
eingabeueberbblick.setText(datensatz.valuesToString());
);
}
// Datepicker Hilfsmethoden
// calendar object mit Daten aus Datepicker
private void updateCalendarFromDatepicker(Calendar cal3, DatePicker dp)
cal3.set(Calendar.YEAR, dp.getYear());
cal3.set(Calendar.MONTH, dp.getMonth());
cal3.set(Calendar.DAY_OF_MONTH, dp.getDayOfMonth());
// here is the issue: pb is handed over but the Calendar Object not
private void updateDatepickerFromCalendar(Calendar cal2, DatePicker dp)
dp.updateDate(cal2.YEAR, cal2.MONTH, cal2.DAY_OF_MONTH);
Thank you in advance.
This question already has an answer here:
Java Calendar always shows the same time
5 answers
Can't add days to Calendar
1 answer
java android calendar
java android calendar
asked Nov 11 at 8:40
Peter
11
11
marked as duplicate by Ole V.V.
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Nov 12 at 7:40
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Ole V.V.
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Nov 12 at 7:40
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
Can you usejava.time
, the modern Java date and time API, with your Android version? Not that it will solve your issue (likely), but it’s much nicer to work with. TheCalendar
class has some design issues and is long outdated.
– Ole V.V.
Nov 11 at 9:59
Changed my mind, using java.time will solve your issue. An error like usingcal2.YEAR
instead ofcal2.get(Calendar.YEAR)
simply isn’t possible with java.time due to its superior design.
– Ole V.V.
Nov 12 at 7:43
add a comment |
Can you usejava.time
, the modern Java date and time API, with your Android version? Not that it will solve your issue (likely), but it’s much nicer to work with. TheCalendar
class has some design issues and is long outdated.
– Ole V.V.
Nov 11 at 9:59
Changed my mind, using java.time will solve your issue. An error like usingcal2.YEAR
instead ofcal2.get(Calendar.YEAR)
simply isn’t possible with java.time due to its superior design.
– Ole V.V.
Nov 12 at 7:43
Can you use
java.time
, the modern Java date and time API, with your Android version? Not that it will solve your issue (likely), but it’s much nicer to work with. The Calendar
class has some design issues and is long outdated.– Ole V.V.
Nov 11 at 9:59
Can you use
java.time
, the modern Java date and time API, with your Android version? Not that it will solve your issue (likely), but it’s much nicer to work with. The Calendar
class has some design issues and is long outdated.– Ole V.V.
Nov 11 at 9:59
Changed my mind, using java.time will solve your issue. An error like using
cal2.YEAR
instead of cal2.get(Calendar.YEAR)
simply isn’t possible with java.time due to its superior design.– Ole V.V.
Nov 12 at 7:43
Changed my mind, using java.time will solve your issue. An error like using
cal2.YEAR
instead of cal2.get(Calendar.YEAR)
simply isn’t possible with java.time due to its superior design.– Ole V.V.
Nov 12 at 7:43
add a comment |
1 Answer
1
active
oldest
votes
This example can help you.
DatePickerDialog datePickerDialog = new DatePickerDialog[1];
Calendar c = Calendar.getInstance();
int mYear = c.get(Calendar.YEAR); // current year
int mMonth = c.get(Calendar.MONTH); // current month
int mDay = c.get(Calendar.DAY_OF_MONTH); // current day
// date picker dialog
datePickerDialog[0] = new DatePickerDialog(RegistrationActivity.this,
new DatePickerDialog.OnDateSetListener()
@Override
public void onDateSet(DatePicker view, int year,
int monthOfYear, int dayOfMonth)
// set day of month , month and year value in the edit text
dateOfBirth.setText(year + "-"+(monthOfYear + 1)
+ "-" + dayOfMonth);
, mYear, mMonth, mDay);
datePickerDialog[0].show();
How does it help? Asking because I don’t see it and also because an answer should always explain how it helps.
– Ole V.V.
Nov 11 at 9:56
Thank you Ole. Maybe I did not explain my beginner Java question right. I have the impression that in the method "updateDatepickerFromCalendar" the Calendar object is not using the passed object testDatum but the passed object for the datepicker is used.
– Peter
Nov 11 at 17:23
1
Hi, I got the problem. The following line is wrong:dp.updateDate(cal2.YEAR, cal2.MONTH, cal2.DAY_OF_MONTH);
and should be replaced bydp.updateDate(cal2.get(Calendar.YEAR), cal2.get(Calendar.MONTH), cal2.get(Calendar.DAY_OF_MONTH));
– Peter
Nov 12 at 0:02
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
This example can help you.
DatePickerDialog datePickerDialog = new DatePickerDialog[1];
Calendar c = Calendar.getInstance();
int mYear = c.get(Calendar.YEAR); // current year
int mMonth = c.get(Calendar.MONTH); // current month
int mDay = c.get(Calendar.DAY_OF_MONTH); // current day
// date picker dialog
datePickerDialog[0] = new DatePickerDialog(RegistrationActivity.this,
new DatePickerDialog.OnDateSetListener()
@Override
public void onDateSet(DatePicker view, int year,
int monthOfYear, int dayOfMonth)
// set day of month , month and year value in the edit text
dateOfBirth.setText(year + "-"+(monthOfYear + 1)
+ "-" + dayOfMonth);
, mYear, mMonth, mDay);
datePickerDialog[0].show();
How does it help? Asking because I don’t see it and also because an answer should always explain how it helps.
– Ole V.V.
Nov 11 at 9:56
Thank you Ole. Maybe I did not explain my beginner Java question right. I have the impression that in the method "updateDatepickerFromCalendar" the Calendar object is not using the passed object testDatum but the passed object for the datepicker is used.
– Peter
Nov 11 at 17:23
1
Hi, I got the problem. The following line is wrong:dp.updateDate(cal2.YEAR, cal2.MONTH, cal2.DAY_OF_MONTH);
and should be replaced bydp.updateDate(cal2.get(Calendar.YEAR), cal2.get(Calendar.MONTH), cal2.get(Calendar.DAY_OF_MONTH));
– Peter
Nov 12 at 0:02
add a comment |
This example can help you.
DatePickerDialog datePickerDialog = new DatePickerDialog[1];
Calendar c = Calendar.getInstance();
int mYear = c.get(Calendar.YEAR); // current year
int mMonth = c.get(Calendar.MONTH); // current month
int mDay = c.get(Calendar.DAY_OF_MONTH); // current day
// date picker dialog
datePickerDialog[0] = new DatePickerDialog(RegistrationActivity.this,
new DatePickerDialog.OnDateSetListener()
@Override
public void onDateSet(DatePicker view, int year,
int monthOfYear, int dayOfMonth)
// set day of month , month and year value in the edit text
dateOfBirth.setText(year + "-"+(monthOfYear + 1)
+ "-" + dayOfMonth);
, mYear, mMonth, mDay);
datePickerDialog[0].show();
How does it help? Asking because I don’t see it and also because an answer should always explain how it helps.
– Ole V.V.
Nov 11 at 9:56
Thank you Ole. Maybe I did not explain my beginner Java question right. I have the impression that in the method "updateDatepickerFromCalendar" the Calendar object is not using the passed object testDatum but the passed object for the datepicker is used.
– Peter
Nov 11 at 17:23
1
Hi, I got the problem. The following line is wrong:dp.updateDate(cal2.YEAR, cal2.MONTH, cal2.DAY_OF_MONTH);
and should be replaced bydp.updateDate(cal2.get(Calendar.YEAR), cal2.get(Calendar.MONTH), cal2.get(Calendar.DAY_OF_MONTH));
– Peter
Nov 12 at 0:02
add a comment |
This example can help you.
DatePickerDialog datePickerDialog = new DatePickerDialog[1];
Calendar c = Calendar.getInstance();
int mYear = c.get(Calendar.YEAR); // current year
int mMonth = c.get(Calendar.MONTH); // current month
int mDay = c.get(Calendar.DAY_OF_MONTH); // current day
// date picker dialog
datePickerDialog[0] = new DatePickerDialog(RegistrationActivity.this,
new DatePickerDialog.OnDateSetListener()
@Override
public void onDateSet(DatePicker view, int year,
int monthOfYear, int dayOfMonth)
// set day of month , month and year value in the edit text
dateOfBirth.setText(year + "-"+(monthOfYear + 1)
+ "-" + dayOfMonth);
, mYear, mMonth, mDay);
datePickerDialog[0].show();
This example can help you.
DatePickerDialog datePickerDialog = new DatePickerDialog[1];
Calendar c = Calendar.getInstance();
int mYear = c.get(Calendar.YEAR); // current year
int mMonth = c.get(Calendar.MONTH); // current month
int mDay = c.get(Calendar.DAY_OF_MONTH); // current day
// date picker dialog
datePickerDialog[0] = new DatePickerDialog(RegistrationActivity.this,
new DatePickerDialog.OnDateSetListener()
@Override
public void onDateSet(DatePicker view, int year,
int monthOfYear, int dayOfMonth)
// set day of month , month and year value in the edit text
dateOfBirth.setText(year + "-"+(monthOfYear + 1)
+ "-" + dayOfMonth);
, mYear, mMonth, mDay);
datePickerDialog[0].show();
answered Nov 11 at 9:03
Vishal Sharma
7692212
7692212
How does it help? Asking because I don’t see it and also because an answer should always explain how it helps.
– Ole V.V.
Nov 11 at 9:56
Thank you Ole. Maybe I did not explain my beginner Java question right. I have the impression that in the method "updateDatepickerFromCalendar" the Calendar object is not using the passed object testDatum but the passed object for the datepicker is used.
– Peter
Nov 11 at 17:23
1
Hi, I got the problem. The following line is wrong:dp.updateDate(cal2.YEAR, cal2.MONTH, cal2.DAY_OF_MONTH);
and should be replaced bydp.updateDate(cal2.get(Calendar.YEAR), cal2.get(Calendar.MONTH), cal2.get(Calendar.DAY_OF_MONTH));
– Peter
Nov 12 at 0:02
add a comment |
How does it help? Asking because I don’t see it and also because an answer should always explain how it helps.
– Ole V.V.
Nov 11 at 9:56
Thank you Ole. Maybe I did not explain my beginner Java question right. I have the impression that in the method "updateDatepickerFromCalendar" the Calendar object is not using the passed object testDatum but the passed object for the datepicker is used.
– Peter
Nov 11 at 17:23
1
Hi, I got the problem. The following line is wrong:dp.updateDate(cal2.YEAR, cal2.MONTH, cal2.DAY_OF_MONTH);
and should be replaced bydp.updateDate(cal2.get(Calendar.YEAR), cal2.get(Calendar.MONTH), cal2.get(Calendar.DAY_OF_MONTH));
– Peter
Nov 12 at 0:02
How does it help? Asking because I don’t see it and also because an answer should always explain how it helps.
– Ole V.V.
Nov 11 at 9:56
How does it help? Asking because I don’t see it and also because an answer should always explain how it helps.
– Ole V.V.
Nov 11 at 9:56
Thank you Ole. Maybe I did not explain my beginner Java question right. I have the impression that in the method "updateDatepickerFromCalendar" the Calendar object is not using the passed object testDatum but the passed object for the datepicker is used.
– Peter
Nov 11 at 17:23
Thank you Ole. Maybe I did not explain my beginner Java question right. I have the impression that in the method "updateDatepickerFromCalendar" the Calendar object is not using the passed object testDatum but the passed object for the datepicker is used.
– Peter
Nov 11 at 17:23
1
1
Hi, I got the problem. The following line is wrong:
dp.updateDate(cal2.YEAR, cal2.MONTH, cal2.DAY_OF_MONTH);
and should be replaced by dp.updateDate(cal2.get(Calendar.YEAR), cal2.get(Calendar.MONTH), cal2.get(Calendar.DAY_OF_MONTH));
– Peter
Nov 12 at 0:02
Hi, I got the problem. The following line is wrong:
dp.updateDate(cal2.YEAR, cal2.MONTH, cal2.DAY_OF_MONTH);
and should be replaced by dp.updateDate(cal2.get(Calendar.YEAR), cal2.get(Calendar.MONTH), cal2.get(Calendar.DAY_OF_MONTH));
– Peter
Nov 12 at 0:02
add a comment |
Can you use
java.time
, the modern Java date and time API, with your Android version? Not that it will solve your issue (likely), but it’s much nicer to work with. TheCalendar
class has some design issues and is long outdated.– Ole V.V.
Nov 11 at 9:59
Changed my mind, using java.time will solve your issue. An error like using
cal2.YEAR
instead ofcal2.get(Calendar.YEAR)
simply isn’t possible with java.time due to its superior design.– Ole V.V.
Nov 12 at 7:43