Elegant solution to retrieve custom date and time?

Posted by kefs on Stack Overflow See other posts from Stack Overflow or by kefs
Published on 2010-05-27T09:24:21Z Indexed on 2010/05/27 9:51 UTC
Read the original article Hit count: 172

Filed under:
|

I am currently using a date and time picker to retrieve a user-submitted date and time, and then I set a control's text to the date and time selected.

I am using the following code:

new DatePickerDialog(newlog3.this, d, calDT.get(Calendar.YEAR), calDT.get(Calendar.MONTH), calDT.get(Calendar.DAY_OF_MONTH)).show();

new TimePickerDialog(newlog3.this, t, calDT.get(Calendar.HOUR_OF_DAY), calDT.get(Calendar.MINUTE), true).show();

optCustom.setText(fmtDT.format(calDT.getTime())); 

Now, while the above code block does bring up the date and time widgets and sets the text, the code block is being executed in full before the user can select the date.. ie: It brings up the date box first, then the time box over that, and then updates the text, all without any user interaction. I would like the date widget to wait to execute the time selector until the date selection is done, and i would like the settext to execute only after the time widget is done.

How is this possible? Or is there is a more elegant solution that is escaping me?

Edit: This is the code for DatePickerDialog/TimePickerDialog which is located within the class:

 DatePickerDialog.OnDateSetListener d=new DatePickerDialog.OnDateSetListener() { 
        public void onDateSet(DatePicker view, int year, int monthOfYear, 
                    int dayOfMonth) { 
            calDT.set(Calendar.YEAR, year); 
            calDT.set(Calendar.MONTH, monthOfYear); 
            calDT.set(Calendar.DAY_OF_MONTH, dayOfMonth); 
          //updateLabel(); 
        } 
      };   
 TimePickerDialog.OnTimeSetListener t=new TimePickerDialog.OnTimeSetListener() { 
        public void onTimeSet(TimePicker view, int hourOfDay, 
                             int minute) { 
            calDT.set(Calendar.HOUR_OF_DAY, hourOfDay); 
            calDT.set(Calendar.MINUTE, minute); 
          //updateLabel(); 
        } 
      };  

Thanks in advance

© Stack Overflow or respective owner

Related posts about android

Related posts about android-sdk