Only getting DatePickerDialog's value when Done button is being pressed

By referring in API demo, I tend to show date picker widget through the following way.

private void initDateTextView() {
    dateTextView.setOnClickListener(new View.OnClickListener() {
        public void onClick(View arg0) {

protected Dialog onCreateDialog(int id) {
    switch (id) {
    case DATE_DIALOG_ID:
       // set date picker as current date
       return new DatePickerDialog(this, datePickerListener, 
                     this.year, this.month,;
    return null;

protected void onPrepareDialog(int id, Dialog dialog) {
    switch (id) {
    case DATE_DIALOG_ID:
        ((DatePickerDialog)dialog).updateDate(this.year, this.month,;

private static final int DATE_DIALOG_ID = 0;
private final 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) {
        Log.i("CHEOK", selectedYear + ", " + selectedMonth + ", " + selectedDay);

However, I realize, onDateSet will always be called, with latest spinner selected date, regardless I am pressing dialog's Done button, or pressing the phone's soft back button.

I am only interested in getting the selected date, when user pressing Done button, but not back button.

Is there any way I can achieve so?


This seems to be a bug in the framework as discussed in this post (with a suggested workaround included).

Need Your Help

Extracting sequence header from mpeg video file

c mpeg-2

I am new too mpeg2dec and I Have been trying to extract sequence header from a video file with mpeg2.h(from libmpeg2) but not getting anywhere.

MVC 3 File upload validation fires incorrectly

c# post file-upload httppostedfilebase

I have a file upload feature in my MVC 3 web application and I'm trying to validate FileSize and FileType using those attributes:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.