0

I'm trying to remove the day row in my spinner. I'm setting

android:calendarViewShown="false"
android:datePickerMode="spinner"

so that it uses the spinner mode. Before I was using reflection like this:

        Field[] fields = DatePicker.class.getDeclaredFields();
        try {
            String[] s = new String[] {"01","02","03","04","05","06","07","08","09","10","11","12"};
            for (Field field : fields) {
                field.setAccessible(true);
                if (TextUtils.equals(field.getName(), "mMonthSpinner")) {
                    NumberPicker monthPicker = (NumberPicker) field.get(this);
                    monthPicker.setDisplayedValues(s);
                }
                if (TextUtils.equals(field.getName(), "mShortMonths")) {
                    field.set(this, s);
                }
                if (TextUtils.equals(field.getName(), "mDaySpinner") || TextUtils.equals(field.getName(), "mDayPicker")) {
                    ((View) field.get(this)).setVisibility(GONE);
                }
            }
        }

but now, with Lollipop, those fields don't exist anymore.

Any idea on how to tackle this problem?

Dlleixap
  • 101
  • 5

2 Answers2

0

There isn't a solution for Android 5.0+ with the DatePicker for the time being. You could try doing it with the DateSlider, so you don't have to code your own DatePicker. If you use the MonthYearDateSlider, you should be able to accomplish what you need.

actaram
  • 2,038
  • 4
  • 28
  • 49
0

I found a solution by using reflection. I'm not a fan of it but well, it solves it for now. I basically found this answer: Android: how to change the color of the datepicker divider?

Community
  • 1
  • 1
Dlleixap
  • 101
  • 5
  • 1
    Any solution involving reflection may cause your app to a) crash or b) not work on random devices or OS versions. You should never do this in a production app. – alanv Mar 25 '15 at 17:39
  • Sure, of course this should never be done in a production app. So, I see you are a software engineer working at google on the Android framework's UI toolkit and Material theme(you seem the right guy to solve this issue). Could you also aport something different on what we all already know? Thanks @alanv – Dlleixap Mar 27 '15 at 13:09
  • It's simply not supported by the framework widget. The other solution here that recommends using a custom widget is the best approach. – alanv Mar 27 '15 at 19:27