how to update the date in android DatePicker widget - android

Hey,
I want to update the date to a year before 1970.
the updateDate function wants a date since 1970.
the widget itself allow you to select 1900-2100 (from what i read you can change it also using an xml to describe the control)
any solutions?
if not, what widget do you use to select date (e.g. birth date...)
Thanks.

Just use a negative number when you pass in the years.

Related

Selecting some dates in Calendar while initializing it

I am using CalenderView in android. I have a list of predefined dates as ["2019-02-15","2019-02-16","2019-02-17"]. When Calender is initialized and shown on Activity/fragment i want this dates to be selected.How to achieve this.
I am initializing calender this way
calender=v.findViewById(R.id.cal);
calender.setMinDate(System.currentTimeMillis()-1000);
How to achieve this ?
Looking into the Android API Reference you find this function:
CalendarView.setDate(long date)
Sets the selected date in milliseconds since January 1, 1970 00:00:00 in TimeZone.getDefault() time zone. https://developer.android.com/reference/android/widget/CalendarView.html#setDate(long)
So in your case you should call:
calender.setDate(long date);
In order to get the milliseconds, you should first parse your date string and then convert them to milliseconds.
Additionally I am not sure and I dont't think that it is possible to select more than one date at a time.
You cannot disable specific dates in the default CalendarView of android, for that you've to fork that widget and do your customisation. Then the other option is to use third party libraries like
material-calendarview
Using this library you can easily disable custom dates and apply custom background color and so on.
Material-Calendar-View
This is also other third party option which provides multiple date selection and so on.

How can i disable specific date

I want to disable the specific dates which user selected in another date picker
I mean user selects date in first date in date picker and another date picker sets minimum date?
That functionality does not available in Android DatePicker. You need to use a custom date picker.
You can use MaterialDateTimePicker library, here you can set an option to disable specific dates by using setDisabledDays() API.
For Example:
datePicker.setDisabledDays(Calendar[] days)
You need to pass array of Calendar days as an parameter which should contains all the disable dates.
you can use setMinDate() function to set the minimum date in date picker.

DatePicker with Date Only

I want to get a date data from a form but only the date, not including the month nor the year. Can I use datepicker in the form but with the date only? If it's not possible, what the efficient way to get date information from a form ? Thanks
What you are looking for is a NumberPicker, but it's only
available starting from API level 11.
Alternatively:
You can use an EditText, with inputType="number", and do you
checking of being in the 1..31 range in code.
You can use a SeekBar, and display the value next to it
dynamically.
You can use a Spinner, and list the 31 possibilities.

Android DatePickerDialog to a year of history

I'm coding an android app about the egyptian history, and I want to add a DatePicker in a dialog, where I will show years, and whenever the user sets a year, it shows in the layout the events in that year . If he changes the year, the event changes ...etc
It is a historical app, and I don't know how to do it!
I need help.
According to the doc (http://developer.android.com/reference/android/widget/DatePicker.html)
You can set min and max date according to the era you want to cover:
android:maxDate The minimal date shown by this calendar view in mm/dd/yyyy format.
android:minDate The minimal date shown by this calendar view in mm/dd/yyyy format.
And then use the onDateChangedListener to display the correct Layout.
http://developer.android.com/reference/android/widget/DatePicker.OnDateChangedListener.html
As you want to use only a year, I would advise to use a NumberPickerDialog instead.
DatePicker is maybe "too much" for your use case.

Date Picker in Android

I want to display a date picker for selecting date of birth,so as to user restricted to choose future date.currently date picker displays all dates including future also.i want to show the dates up to current dates only.
Thanks.
I recommend the Date Picker Dialog? Then just extend it to fit your requirements.
It's some what hard to explain how to create a Date Picker. What's better is looking at the sample code from the Android API Demos which shows you how to do a Date Picket and much more. You can figure out how to download these API Demos at: http://developer.android.com/resources/samples/get.html. Good luck!
Use the setMaxDate function, and set that to the current date
Datepicker dp = (DatePicker) v.findViewById(R.id.date_picker);
// Set it to only show past dates...
dp.setMaxDate(System.currentTimeMillis());
(reference)

Categories

Resources