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
Add this line to your date picker xml
android:calendarViewShown="false"
This will remove the Calendar.
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
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);
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" />
Add
android:datePickerMode="spinner"
instead of
android:calenderViewShown="false"
来源:https://stackoverflow.com/questions/13670695/why-does-the-datepicker-add-a-calendar-in-my-view