문제

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

도움이 되었습니까?

해결책

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.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top