Why does the datepicker add a calendar in my view?

Guigui picture Guigui · Dec 2, 2012 · Viewed 14.7k times · Source


I am starting to learn how to develop on Android. It is pretty straightforward but I'm facing an issue I did not find any mention anywhere...

I have a view :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
     android:paddingLeft="16dp"
android:paddingRight="16dp"
android:orientation="vertical">

    <EditText
        android:id="@+id/editNomProduit"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:hint="@string/ht_nom_produit" />



    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
     android:paddingLeft="16dp"
android:paddingRight="16dp"
android:orientation="horizontal">

        <TextView
            android:id="@+id/labelQuantiteProduitEdit"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/labelQuantiteProduitEdit"
            android:textAppearance="?android:attr/textAppearanceMedium" />

<EditText
        android:id="@+id/editQuantite"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:inputType="number" />

<Spinner
    android:id="@+id/spinnerUnite"
    android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

    </LinearLayout>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
     android:paddingLeft="16dp"
android:paddingRight="16dp"
android:orientation="horizontal">

        <TextView
            android:id="@+id/labeDateAchatProduitEdit"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/labelDateAchatProduitEdit"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <DatePicker
            android:id="@+id/dpDateAchatProduit"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

</LinearLayout>

</LinearLayout>

Which displayed a datepicker. The thing is that the date picker seems to add a Calendar besides the classic rollers for the date picker (see picture). I don't want this view, juste the roller for the date. Am I usign the date picker in the wrong way or is this the orignal behavior ? Thanks !

Guillaume

Date picker with canlendar

Answer

CocoNess picture CocoNess · Dec 2, 2012

Add this line to your date picker xml

android:calendarViewShown="false"

This will remove the Calendar.