Android - OnDateChangedListener - how do you set this?
Once you've created your DatePicker
, you need to initialize it with the date you want to display at first. That's the point at which you can add your listener.
See DatePicker.init(int, int, int, OnDateChangedListener)
.
Update
26 API allows to set listener: DatePicker.setOnDateChangedListener()
DatePicker.OnDateChangedListener called twice
When I test my application, method onDateSet called twice after accept the date selection and once when I canceled.
I added a validation in the method onDateSet with parameter view, something like this
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth){
if (view.isShown()) {
updateDate(year, monthOfYear, dayOfMonth);
}
}
What is android Date changed Listener Event?
You could refer to this :
Android - OnDateChangedListener - how do you set this?
Android DatePicker question
http://developer.android.com/reference/android/widget/DatePicker.OnDateChangedListener.html
Android DatePicker how to set listener and selected date to show and set to and from date
The key word you are looking for is "Range".
Here a link for an android library that marks that range between dates.
https://github.com/borax12/MaterialDateRangePicker
DatePickerDialog cannot implement OnDateSetListener on MaterialLibrary
From https://github.com/rey5137/material/blob/master/lib/src/main/java/com/rey/material/widget/DatePicker.java#L430 it looks like the function is called setOnDateChangedListener
and you need to implement OnDateChangedListener
:
/**
* Set the listener will be called when the selected date is changed.
* @param listener The {@link DatePicker.OnDateChangedListener} will be called.
*/
public void setOnDateChangedListener(OnDateChangedListener listener){
mOnDateChangedListener = listener;
}
and from https://github.com/rey5137/material/blob/master/lib/src/main/java/com/rey/material/widget/DatePicker.java#L72 is the interface to implement:
/**
* Interface definition for a callback to be invoked when the selected date is changed.
*/
public interface OnDateChangedListener {
/**
* Called when the selected date is changed.
* @param oldDay The day value of old date.
* @param oldMonth The month value of old date.
* @param oldYear The year value of old date.
* @param newDay The day value of new date.
* @param newMonth The month value of new date.
* @param newYear The year value of new date.
*/
public void onDateChanged(int oldDay, int oldMonth, int oldYear, int newDay, int newMonth, int newYear);
}
Related Topics
Java.Lang.Noclassdeffounderror: Failed Resolution Of: Landroid/Support/V4/Os/Buildcompat
App Getting Stuck with E/Com.Facebook.Internal.Attributionidentifiers
Broadcast Receiver Not Working in Ics If the App Is Not Started Atleast Once
How to Filter the Data in Realm Adapter
How to Launch an Activity Without a Ui
How to Have a Listview/Recyclerview Inside a Parent Recyclerview
Android 4.0, Text on the Action Bar Never Shows
How to Extract the File Name from Uri Returned from Intent.Action_Get_Content
Android Wear App Not Installing Through Handset
Retrieve Contact Phone Number from Uri in Android
Android Marshmallow: Changing Permissions at Run Time Crashes App
Best Way to Save Large Amount of Data Locally in Unity3D Android
Achartengine - Can't Figure How to Use Dates as X Axis - the File I Save Is Empty
Android Recyclerview: Change Layout File List to Grid Onoptionitemselected