setMinDate and setMaxDate work incorrectly
VashchenkoAndrey opened this issue · 6 comments
VashchenkoAndrey commented
When I setMaxDate(), picker show max year = current year - 70 years. But getDate() return correct value.
outofsleepexception commented
I've the same issue.
ikurek commented
I can confirm this
TanveerTaj commented
Facing same issue...
agustinsivoplas commented
Same issue here
chinalwb commented
Yes, I have the same issue. But,
Hey guys, maybe you want to tryout this:
import android.content.Context
import android.util.AttributeSet
import com.github.florent37.singledateandtimepicker.widget.WheelYearPicker
class CustomWheelYearPicker(
context: Context,
attrs: AttributeSet
): WheelYearPicker(context, attrs) {
override fun setMinYear(minYear: Int) {
super.setMinYear(minYear)
updateAdapter()
}
override fun setMaxYear(maxYear: Int) {
super.setMaxYear(maxYear)
updateAdapter()
}
}
- Make use of this
CustomWheelYearPicker
in your layout:
<your.package.CustomWheelYearPicker
android:id="@+id/yearPicker"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_weight="2"
app:wheel_atmospheric="true"
app:wheel_item_align="center" />
- Then call
setMaxDate
/setMinDate
to check if it works well.
tobbelindberg commented
I continued on @chinalwb suggestion and ended up with:
class CustomWheelYearPicker(
context: Context, attrs: AttributeSet? = null
) : WheelYearPicker(context, attrs) {
override fun setShowOnlyFutureDate(showOnlyFutureDate: Boolean) {
super.setShowOnlyFutureDate(showOnlyFutureDate)
updateAdapter()
}
override fun setMinYear(minYear: Int) {
super.setMinYear(minYear)
updateAdapter()
}
override fun setMaxYear(maxYear: Int) {
super.setMaxYear(maxYear)
updateAdapter()
}
}
Then I copied single_day_and_time_picker.xml
and modified it like this:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:gravity="center"
android:orientation="horizontal">
<com.github.florent37.singledateandtimepicker.widget.WheelDayPicker
android:id="@+id/daysPicker"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"
android:paddingLeft="5dp"
android:paddingRight="5dp"
app:wheel_atmospheric="true"
app:wheel_item_align="right" />
<com.github.florent37.singledateandtimepicker.widget.WheelDayOfMonthPicker
android:id="@+id/daysOfMonthPicker"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:paddingLeft="5dp"
android:paddingRight="5dp"
app:wheel_atmospheric="true"
app:wheel_item_align="right" />
<com.github.florent37.singledateandtimepicker.widget.WheelMonthPicker
android:id="@+id/monthPicker"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"
android:paddingLeft="5dp"
android:paddingRight="5dp"
app:wheel_atmospheric="true"
app:wheel_item_align="right" />
<com.axessions.app.widget.CustomWheelYearPicker
android:id="@+id/yearPicker"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:paddingLeft="5dp"
android:paddingRight="15dp"
app:wheel_atmospheric="true"
app:wheel_item_align="right" />
<com.github.florent37.singledateandtimepicker.widget.WheelHourPicker
android:id="@+id/hoursPicker"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:paddingLeft="10dp"
android:paddingRight="10dp"
app:wheel_atmospheric="true"
app:wheel_item_align="center" />
<com.github.florent37.singledateandtimepicker.widget.WheelMinutePicker
android:id="@+id/minutesPicker"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:paddingLeft="10dp"
android:paddingRight="10dp"
app:wheel_atmospheric="true"
app:wheel_item_align="center" />
<com.github.florent37.singledateandtimepicker.widget.WheelAmPmPicker
android:id="@+id/amPmPicker"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:paddingLeft="10dp"
android:paddingRight="5dp"
app:wheel_atmospheric="true"
app:wheel_item_align="center"
app:wheel_visible_item_count="2" />
</LinearLayout>
<View
android:id="@+id/dtSelector"
android:layout_width="match_parent"
android:layout_height="@dimen/wheelSelectorHeight"
android:layout_gravity="center_vertical"
android:alpha="0.2"
android:background="@color/picker_default_selector_color" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="@dimen/wheelSelectorHeight"
android:layout_gravity="center_vertical"
android:orientation="vertical">
<View
android:id="@+id/picker_divider_1"
android:layout_width="match_parent"
android:layout_height="@dimen/picker_default_divider_height"
android:layout_alignParentTop="true"
android:background="@drawable/picker_default_divider" />
<View
android:id="@+id/picker_divider_2"
android:layout_width="match_parent"
android:layout_height="@dimen/picker_default_divider_height"
android:layout_alignParentBottom="true"
android:background="@drawable/picker_default_divider" />
</RelativeLayout>
</FrameLayout>
and lastly I override single_day_and_time_picker.xml
layout file in refs.xml
like this:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools">
<item name="single_day_and_time_picker" type="layout" tools:override="true">@layout/view_single_day_and_time_picker_replacement</item>
</resources>
And now I can use the regular SingleDateAndTimePickerDialog
without having to make a huge custom effort with overriding everything and of course year works as expected with min and max date.