24


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

CocoNess
  • 4,213
  • 4
  • 26
  • 43
Guigui
  • 1,105
  • 1
  • 11
  • 21

5 Answers5

69

Add this line to your date picker xml

android:calendarViewShown="false"

This will remove the Calendar.

CocoNess
  • 4,213
  • 4
  • 26
  • 43
6

All you need add under the:

 <datepicker>

method, just add:

 android:calendarViewShown="false"

This will remove the calendar, but keep the scroller.

Hope this helps

2

I had the same problem. I haven't created any xml file. So I fixed by changing the value of calendarviewshow in Activity. Hope it will help somebody.

We can hide the calendar view in DatePicker using two methods.

1 In Layout(XML file)(Thanks to @coconess)

<DatePicker
    android:id="@+id/datepickerv1"
    android:calendarViewShown="false">

2 In Activity(Java file)

Note: If you are not using "calendarViewShow" in xml, follow this step.
DatePicker dp=(DatePicker)findViewById(R.id.datepickerv1);
dp.setCalendarViewShown(false);
Mahendran Sakkarai
  • 8,381
  • 6
  • 44
  • 66
1

Change your datepicker from xml as follows :

<DatePicker
android:id="@+id/dpDateAchatProduit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:calendarViewShown="false" />
Biswajit Karmakar
  • 9,799
  • 4
  • 39
  • 41
1

Add

android:datePickerMode="spinner"

instead of

android:calenderViewShown="false"
bishal
  • 676
  • 7
  • 12