Adding DatePickerDialog to QuizSeFngsAc/vity involves several steps: 1. Define a unique identfier for the dialog within the actvity. 2. Implement the onCreateDialog() method of the ac/vity to return DatePickerDialog when supplied the unique identfier. 3. Implement the onPrepareDialog() method of the actvity to initalize DatePickerDialog with the date of birth preference or the current date. 4. Launch the DatePickerDialog using the showDialog() method, with the unique Dialog identfier
Initialise DatePickerDialog and add OnDateSetListener to implement onDateSet Method for updating the date value. Get current time and set the updated values of year,month and dayofmonth Convert to milliseconds and then to the required format to display.
DatePickerDialog dateDialog = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() { public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { Time dateOfBirth = new Time(); dateOfBirth.set(dayOfMonth, monthOfYear, year); long dtDob = dateOfBirth.toMillis(true); dob.setText(DateFormat.format("MMMM dd, yyyy", dtDob)); Editor editor = mGameSettings.edit(); editor.putLong(GAME_PREFERENCES_DOB, dtDob); editor.commit();
This comment has been removed by the author.
ReplyDeleteAdding DatePickerDialog to QuizSeFngsAc/vity involves several
ReplyDeletesteps:
1. Define a unique identfier for the dialog within the actvity.
2. Implement the onCreateDialog() method of the ac/vity to return DatePickerDialog when supplied the unique identfier.
3. Implement the onPrepareDialog() method of the actvity to initalize DatePickerDialog with
the date of birth preference or the current date.
4. Launch the DatePickerDialog using the
showDialog() method, with the unique Dialog identfier
Calendar now = Calendar.getInstance();
ReplyDeleteDatePickerDialog dateDialog = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
Time dateOfBirth = new Time();
dateOfBirth.set(dayOfMonth, monthOfYear, year);
long dtDob = dateOfBirth.toMillis(true);
dob.setText(DateFormat.format("MMMM dd, yyyy", dtDob));
Editor editor = mGameSettings.edit();
editor.putLong(GAME_PREFERENCES_DOB, dtDob);
editor.commit();
}
}, now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH));
Initialise DatePickerDialog and add OnDateSetListener to implement onDateSet Method for updating the
ReplyDeletedate value.
Get current time and set the updated values of year,month and dayofmonth
Convert to milliseconds and then to the required format to display.
DatePickerDialog dateDialog = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
Time dateOfBirth = new Time();
dateOfBirth.set(dayOfMonth, monthOfYear, year);
long dtDob = dateOfBirth.toMillis(true);
dob.setText(DateFormat.format("MMMM dd, yyyy", dtDob));
Editor editor = mGameSettings.edit();
editor.putLong(GAME_PREFERENCES_DOB, dtDob);
editor.commit();
}
}, now.get(Calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH));
This comment has been removed by the author.
ReplyDeleteCalendar now = Calendar.geiInstance();
ReplyDeleteDatePickerDialog dateDialog = new DatePickerDialog(this, new DatePickerDialog.onDateSetListerner() {
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
Time dateOfBirth = new Time();
dateOfBirth.set(dateOfMonth, monthOfYear, year);
long dtDOB = dateOfBirth.toMills(true);
dob.setText(DateFormat.format("MMMM dd, yyyy", dtDob));
Editor editor = mGameSettings.edit();
editor.putLong(GAME_PREFERENCEs_DOB, dtDOB);
editor.commit();
}
}, now.get(calendar.YEAR), now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH)