Pratheesh
Pratheesh

Reputation: 814

DatePicker calender view in android

Hi I am having some strange problem here. I am trying to remove the calenderview from my datepicker in android. As most of the posts in stackoverflow says to add this line:

android:calenderViewShown="false"

But when I am adding this line I am getting the error.

error: No resource identifier found for attribute 'calendarViewShown' in package 'android'

If I am trying to add this through code using this line

picker.setCalendarViewShown(false);

then it shows the error:

The method setCalendarViewShown(boolean) is undefined for the type DatePicker

My Manifest entry is like this

<uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="23" />

My full XML code is like this

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical" >

            <DatePicker
                android:id="@+id/schedule"
                android:calendarViewShown="false"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

            <TimePicker
                android:id="@+id/timePicker1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

            <Button
                android:id="@+id/select"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Set Alarm" />
        </LinearLayout>
    </ScrollView>

</RelativeLayout>

I have tried clean and Restarting the eclipse. But of no use. I cannot understand what is the real problem!! Can anyone help me??

Upvotes: 2

Views: 678

Answers (3)

Rahul Chaurasia
Rahul Chaurasia

Reputation: 1641

As the document says -

public void setCalendarViewShown (boolean shown)

Added in API level 11 Sets whether the CalendarView is shown.

Note: Calling this method has no effect when the DatePicker_datePickerMode attribute is set to calendar.

Parameters shown true to show the calendar view, false to hide it

After L, the default mode for DatePicker_datePickerMode is calendar. So, you'll have to make sure that you've selected the correct mode.

To hide the calendar view, first set the datePickerMode to Spinner and then you can call setCalendarViewShown(false).

Upvotes: 1

Raghav Mehta
Raghav Mehta

Reputation: 66

Right denis_lor .. Try this code first..

<DatePicker
    android:id="@+id/schedule"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:datePickerMode="spinner"
    android:calendarViewShown="false" />

and still not got result than try to programmatically in Java, like..

dialogDatePicker.getDatePicker().setSpinnersShown(true);
dialogDatePicker.getDatePicker().setCalendarViewShown(false); 

Hope it will help..

Upvotes: 0

denis_lor
denis_lor

Reputation: 6547

Try to use android:datePickerMode="spinner". As it's an API 21 attribute, don't forget to make a new layout-v21 folder in your res folder.

<DatePicker
    android:id="@+id/schedule"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:datePickerMode="spinner"
    android:calendarViewShown="false" />

Upvotes: 2

Related Questions