aravind varma
aravind varma

Reputation: 90

when using datepicker in android 4.0 and above..how to avoid the calender view

i have done a project in android 2.2 which contains a date picker and set the properties for it according to he size of screen but when i installed it in android 4.0...the date picker view includes a calender view ....what to do to avoid the calender view along with datepicker in android 4.0...below are the images of date picker in 2.2 and 4.1

android 2.2 image of date picker

android 4.1 image of date picker

Upvotes: 4

Views: 6362

Answers (4)

bishal
bishal

Reputation: 716

To avoid the Calendar in your DatePicker for later APIs

Add

android:datePickerMode="spinner"

instead of

android:calenderViewShown="false"

in your layout XML for the DatePicker widget.

Upvotes: 0

In Case that you have instance of DatePicker you must write only this in your method `

        int currentapiVersion = android.os.Build.VERSION.SDK_INT;
        if (currentapiVersion >= 11) {
            yourDatePickerInstance.setCalendarViewShown(false);
        }`

Upvotes: 1

tobias
tobias

Reputation: 2362

Use the code of Raval. But to run it below Android version 11, do following:

int currentapiVersion = android.os.Build.VERSION.SDK_INT;
        if (currentapiVersion >= 11) {
          try {
            Method m = datePicker.getClass().getMethod("setCalendarViewShown", boolean.class);
            m.invoke(datePicker, false);
          }
          catch (Exception e) {} // eat exception in our case
        }

Now you have it working on all Android versions (Above API > 3)

Upvotes: 3

Chirag
Chirag

Reputation: 56925

You can use yourDatepicker.setCalendarViewShown(false);

This method works in Api >= 11 .

Upvotes: 12

Related Questions