Why does the datepicker add a calendar in my view?

╄→尐↘猪︶ㄣ 提交于 2019-12-04 15:29:50

问题



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


回答1:


Add this line to your date picker xml

android:calendarViewShown="false"

This will remove the Calendar.




回答2:


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




回答3:


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);



回答4:


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" />



回答5:


Add

android:datePickerMode="spinner"

instead of

android:calenderViewShown="false"


来源:https://stackoverflow.com/questions/13670695/why-does-the-datepicker-add-a-calendar-in-my-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!