-2

i've an app that has a DatePickerDialog. when i run the same code on different devices run different androids i get a different dialog. I understand the fact that in different versions of android the same widget can look athetically different but why should the wigets features differ from the same source code.

Below are the two widgets the first is android 2.3.3 and the second is in Android 4.0.4. I know they look different, but i want the date refected at the top of the widget as it is in the 2.3.3 version, but in the 4.0.4. Why is "Thursday, 08/Nov/2012" not displayed in 4.0.4?

2.3.3

4.0.4

turtleboy
  • 8,210
  • 27
  • 100
  • 199

2 Answers2

1

Why is "Thursday, 08/Nov/2012" not displayed in 4.0.4?

Only the person who made that decision would be able to answer. If I had to take a stab at it I would guess they thought it was prettier somehow.

You are of course free to create your own date picker dialog that displays all of the information you want it to exactly how you want it to though. That is probably the best route to take if you are looking to get your application to be 100% consistent across all API versions.

EDIT:

Here is the source code for DatePickerDialog

It looks like you could override onDateChanged() of the DatePickerDialog to get the effect you want. am working on a sample chunk of code to post now.

EDIT AGAIN:

Ok here is a snippet that is making it work correctly on a 4.0.3 device that I have access to.

   df = DateFormat.getDateInstance(DateFormat.FULL);
   mCal = Calendar.getInstance();
   // Create a date picker dialog
   DatePickerDialog datePickerDialog = new DatePickerDialog(this,datePickerDialogListener, year, month, day){
       @Override
       public void onDateChanged(DatePicker view, int year,int month, int day){
           mCal.set(Calendar.YEAR, year);
            mCal.set(Calendar.MONTH, month);
            mCal.set(Calendar.DAY_OF_MONTH, day);
           setTitle(df.format(mCal.getTime()));
       }
   };

You'll have to add in the code to set it the first time right before the dialog is shown.

FoamyGuy
  • 46,603
  • 18
  • 125
  • 156
  • DatePickerDialog has a `setTitle()` method that you can use to set a string up there. where you'll need to do that depends a bit on how it needs to behave. Does the date in the title need to change as the user changes the date with the buttons? – FoamyGuy Nov 08 '12 at 15:12
  • yes it does need to change and also display the day of week. It's for carers that are looking up their rotas. It would be nice for them just to hit the +- buttons and not have to work out in their head what the date was last tuesday – turtleboy Nov 08 '12 at 15:15
  • The DatePicker object has an onChanged() listener if you can get a reference to the DatePicker used by the dialog you should be able to call init() on it and pass it your own listener which can set the title of the dialog whenever the date is changed. See this question for info about DatePicker http://stackoverflow.com/questions/2051153/android-ondatechangedlistener-how-do-you-set-this – FoamyGuy Nov 08 '12 at 15:25
  • Turns out DatePickerDialog actually implements the onDateChangedListener() so you can directly override that callback to have make it put the date into the title, see my last edit. – FoamyGuy Nov 08 '12 at 15:47
0

Originally (2.3 and earlier [honeycomb?]) the title was automatically updated to the current date. I think they realized that that might not always be desired (e.g. it's a pain to set a "plain text" title in 2.3, I know) so they changed it to be plain text. You can check both versions of the code: 2.3 and 4.0. I believe it's easier to make it look like 2.3 than 4.0, but you're going to have to customize it.

dmon
  • 30,048
  • 8
  • 87
  • 96