Android DatePicker dialog, date should come from tomorrow - java

Calendar calender = Calendar.getInstance();
final CustomDatePickerDialog pickerDialog = new CustomDatePickerDialog(LabCheckOutActivity.this,
myDateListener, calender.get(Calendar.YEAR), calender.get(Calendar.MONTH),
calender.get(Calendar.DAY_OF_MONTH)+1);
pickerDialog.getDatePicker().setMinDate(System.currentTimeMillis()-1000);
pickerDialog.show();
by Using this code, in dialog date is pointed to tomorrow but user can also select todays date.I want user can select date from tomorrow not today.
public class CustomDatePickerDialog extends DatePickerDialog {
int maxYear;
int maxMonth;
int maxDay;
public CustomDatePickerDialog(Context context, OnDateSetListener callBack, int year, int monthOfYear, int dayOfMonth) {
super(context, callBack, year, monthOfYear, dayOfMonth);
}
public void setMaxDate(long maxDate) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
getDatePicker().setMaxDate(System.currentTimeMillis());
} else {
final Calendar c = Calendar.getInstance();
c.setTimeInMillis(maxDate);
maxYear = c.get(Calendar.YEAR);
maxMonth = c.get(Calendar.MONTH);
maxDay = c.get(Calendar.DAY_OF_MONTH);
}
}
#Override
public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
super.onDateChanged(view, year, monthOfYear, dayOfMonth);
} else {
if (year > maxYear)
view.updateDate(maxYear, maxMonth, maxDay);
if (monthOfYear > maxMonth && year == maxYear)
view.updateDate(maxYear, maxMonth, maxDay);
if (dayOfMonth > maxDay && year == maxYear && monthOfYear == maxMonth)
view.updateDate(maxYear, maxMonth, maxDay);
}
}
}

Use
pickerDialog.getDatePicker().setMinDate(System.currentTimeMillis()+24*60*60*1000);//where 24*60*60*1000 represents the total timestamp for one day
instead of
pickerDialog.getDatePicker().setMinDate(System.currentTimeMillis()-1000);

Please see complete implementation below:
DialogFragment class
public class DatePickerFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener
{
public DatePickerFragment()
{
}
public void setiDateTimeListener(IDateTimeListener iDateTimeListener)
{
this.iDateTimeListener = iDateTimeListener;
}
#Override
public Dialog onCreateDialog(Bundle savedInstanceState)
{
// Use the current date as the default date in the picker
final Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);
DatePickerDialog datePickerDialog = new DatePickerDialog(getActivity(), this, year, month, day);
// Set minimum date as tommorw
datePickerDialog.getDatePicker().setMinDate(System.currentTimeMillis() + 24*60*60*1000);
// If need to set max date then use this also
// datePickerDialog.getDatePicker().setMaxDate(System.currentTimeMillis());
// Create a new instance of DatePickerDialog and return it
return datePickerDialog;
}
#Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth)
{
try
{
String selectedDt = dayOfMonth+"-"+(monthOfYear + 1)+"-"+year;
iDateTimeListener.onDateSet(selectedDt);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
Interface must be implemented in date picker calling class
public interface IDateTimeListener
{
public void onDateSet(String date);
}
Calling dialog fragment
public void showDatePickerDialog()
{
DatePickerFragment datePickerFragment = new DatePickerFragment();
datePickerFragment.setiDateTimeListener(this);
datePickerFragment.show(getActivity().getSupportFragmentManager(),"datePicker");
}

if (CustomVerticalCalendarView.isPreviousDateDisabled()) { // disable previous date disable flow
int daysOfYear = listCalender.get(Calendar.DAY_OF_YEAR);
int currentDate = today.get(Calendar.DAY_OF_YEAR);
int listYear = listCalender.get(Calendar.YEAR);
int currentYear = today.get(Calendar.YEAR);
if (daysOfYear < currentDate || listYear < currentYear) {
checkBox.setEnabled(false);
checkBox.setTextColor(ContextCompat.getColor(checkBox.getContext(), R.color.dark_gray));
}
}
Hope this code helps you.

Related

call DatePicker from helper class to an android activity

Iam using DatePickerDialog in one of my activity and its working fine but now I have to implement it in many activities so I thought to put it in a helper class and extend that function to all activities as good code practice.I have created an interface but couldn't able to use it properly.I have seen another link on stackoverflow but over there they are extending from one class to another class not activity.What I want is I have a helper class where I have put multiple function which Iam using repeatedly in my app and then extend them to any activity according to requirement.So I want to put this datepicker function in HelperClass then then get this function any where in app.Thanku
This is my datePicker function which is currently Iam using in an activity and its working fine
public void datePicker(int day,int month,int year) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
final Calendar myCalendar = Calendar.getInstance();
year = myCalendar.get(Calendar.YEAR);
month = myCalendar.get(Calendar.MONTH);
day = myCalendar.get(Calendar.DAY_OF_MONTH);
}
picker = new DatePickerDialog(RequestTraining.this, new DatePickerDialog.OnDateSetListener() {
#Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
}
}, year, month, day);
picker.getDatePicker().setMinDate(System.currentTimeMillis() - 1000);
picker.show();
}
This is the interface I made
public interface DatePickerListener {
public void onDate(DatePicker view, int year, int monthOfYear, int dayOfMonth);
}
I think, the best approach will be like this
class Utils {
public void datePicker(Context mContext, EditText et) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
final Calendar myCalendar = Calendar.getInstance();
year = myCalendar.get(Calendar.YEAR);
month = myCalendar.get(Calendar.MONTH);
day = myCalendar.get(Calendar.DAY_OF_MONTH);
}
picker = new DatePickerDialog(mContext, new DatePickerDialog.OnDateSetListener() {
#Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
et.setText(dayOfMonth + "/" + (monthOfYear + 1) + "/" + year);
}
}, year, month, day);
picker.getDatePicker().setMinDate(System.currentTimeMillis() - 1000);
picker.show();
}
}
And now just call this method from any class like
Utils.datePicker(this, editText);
Just Need to make an interface callBack and implement it in all of your activities where you need callBack. Then you need to override the method onDateSelected(String date) in your activities which implements callBack interface. Just call the Utils.datePicker(this) where you want .
interface callBack{
onDateSelected(String date);
}
class Utils {
public static void datePicker(callBack call) {
if (android.os.Build.VERSION.SDK_INT >=
android.os.Build.VERSION_CODES.N)
{
final Calendar myCalendar = Calendar.getInstance();
year = myCalendar.get(Calendar.YEAR);
month = myCalendar.get(Calendar.MONTH);
day = myCalendar.get(Calendar.DAY_OF_MONTH);
}
picker = new DatePickerDialog(RequestTraining.this, new
DatePickerDialog.OnDateSetListener() {
#Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int
dayOfMonth) {
trainingDate = dayOfMonth + "/" + (monthOfYear + 1) + "/" + year;
call.onDateSelected(trainingDate);
}
}, year, month, day);
picker.getDatePicker().setMinDate(System.currentTimeMillis() - 1000);
picker.show();
}
}
Hope it will help you.

Android how to show years first in datepicker when onclick the button

datepickerLayout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
final Calendar calendar = Calendar.getInstance();
int yy = calendar.get(Calendar.YEAR);
int mm = calendar.get(Calendar.MONTH);
int dd = calendar.get(Calendar.DAY_OF_MONTH);
DatePickerDialog datePickerDialog = new DatePickerDialog(getContext(),new DatePickerDialog.OnDateSetListener() {
#Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
datePickerDialog.getTouchables().get(0).performClick();
String strdate=year+"-"+(monthOfYear+1)+"-"+dayOfMonth;
}
}, yy, mm, dd);
datePickerDialog.getDatePicker().setMinDate(calendar.getTimeInMillis());
datePickerDialog.show();
}
});
I want to display years in datepicker when button is clicked after selecting the years i want to select date.
You can achieve this simply using below code
DatePickerDialog dialog = new DatePickerDialog(getActivity(), this, year, month, day);
dialog.getDatePicker().getTouchables().get( 0 ).performClick();
Use below class to open dialog
public class DatePickerFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener {
OnDateOfBirthSelection registrationIIFragment;
#Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current date as the default date in the picker
final Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);
// Create a new instance of DatePickerDialog and return it
DatePickerDialog abc = new DatePickerDialog(getActivity(), this, year, month, day);
//18 Years =568,025,136,000 Milliseconds
double diff = System.currentTimeMillis() - 568025136000.0;
abc.getDatePicker().setMaxDate((long) diff);
abc.getDatePicker().getTouchables().get( 0 ).performClick();
return abc;
}
public void onDateSet(DatePicker view, int year, int month, int day) {
// Do something with the date chosen by the user
// tv1.setText("Year: "+view.getYear()+" Month: "+view.getMonth()+" Day: "+view.getDayOfMonth());
registrationIIFragment.onDateOfBirthSelected(view.getDayOfMonth() + " - " + (view.getMonth() + 1) + " - " + view.getYear());
}
public void setCallbackListener(OnDateOfBirthSelection registrationIIFragment) {
this.registrationIIFragment = registrationIIFragment;
}
public interface OnDateOfBirthSelection {
public void onDateOfBirthSelected(String s);
} }
In button click create above class instance and call show method.
DatePickerFragment newFragment = new DatePickerFragment();
newFragment.setCallbackListener(this);
newFragment.show(getSupportFragmentManager(), "datePicker");
above code will display output as below image
Hope this will help thanks

Android Date Picker Fragment can not be set to Custom date

In here 'onClickListner' on 'Image Button' my custom 'DatePickerFragment' is displaying to select the date. Below is the code for
DatePickerFragment.java
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.util.Log;
import android.widget.DatePicker;
import java.util.Calendar;
/**
* Created by Admin on 9/4/18.
*/
public class DatePickerFragment extends DialogFragment
implements DatePickerDialog.OnDateSetListener {
private onDatePickerListener mListener;
private boolean future;
public DatePickerFragment(){
}
// public DatePickerFragment(boolean future){
// this.future=future;
// }
#Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current date as the default date in the picker
final Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
Log.d("DATE_PICKER", " CURRENT_MONTH " + month);
int day = c.get(Calendar.DAY_OF_MONTH);
DatePickerDialog datePickerDialog = new DatePickerDialog(getActivity(), R.style.AppBaseTheme,this, year, month, day);
if(isFuture() ==false){
datePickerDialog.getDatePicker().setMaxDate(System.currentTimeMillis());
}
// Create a new instance of DatePickerDialog and return it
return datePickerDialog;
}
public void onDateSet(DatePicker view, int year, int month, int day) {
// Do something with the date chosen by the user
callListener(year, month, day);
}
public DialogFragment setCallbackListener(onDatePickerListener listener) {
mListener = listener;
return null;
}
private void callListener(int year, int month, int day) {
if (mListener != null) mListener.onDataSet(year, month, day);
}
public boolean isFuture() {
return future;
}
public void setFuture(boolean future) {
this.future = future;
}
public interface onDatePickerListener {
void onDataSet(int year, int month, int day);
}
}
Then I call this 'Fragment' in my 'MainActivity' to set the date to 'EditText' when click on the 'OK' button from the 'DatePickerFragment'.
MainActivity.java
import android.app.TimePickerDialog;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.DialogFragment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.format.Time;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import com.sample.DatePickerFragment;
public class AddInterestedKarmaActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_interested_karma);
ButterKnife.bind(this);
context = this;
EditText dateEdittext = (Edittext)findViewById(R.id.date_edit);
setDate(dateEditText);
}
private void setDate(final EditText dateEditText){
datePickerFragment.setCallbackListener(new DatePickerFragment.onDatePickerListener() {
#Override
public void onDataSet(int year, int month, int day) {
int currentMonth = 0;
if (month == 0) {
currentMonth = 1;
} else if (month == 1) {
currentMonth = 2;
} else if (month == 2) {
currentMonth = 3;
} else if (month == 3) {
currentMonth = 4;
} else if (month == 4) {
currentMonth = 5;
} else if (month == 5) {
currentMonth = 6;
} else if (month == 6) {
currentMonth = 7;
} else if (month == 7) {
currentMonth = 8;
} else if (month == 8) {
currentMonth = 9;
} else if (month == 9) {
currentMonth = 10;
} else if (month == 10) {
currentMonth = 11;
} else if (month == 11) {
currentMonth = 12;
} else if (month == 12) {
}
dateEditText.setText(day + "/" + currentMonth + "/" + year);
}
});
}
DialogFragment datePicker = datePickerFragment;
datePicker.show(getSupportFragmentManager(), "datePicker");
}
private void setTime(final EditText timeEditText){
final Calendar c = Calendar.getInstance();
mHour = c.get(Calendar.HOUR_OF_DAY);
mMinute = c.get(Calendar.MINUTE);
TimePickerDialog timePickerDialog = new TimePickerDialog(context,
new TimePickerDialog.OnTimeSetListener() {
#Override
public void onTimeSet(TimePicker view, int hourOfDay,
int minute) {
String curTime = String.format("%02d:%02d", hourOfDay, minute);
timeEditText.setText(curTime);
}
}, mHour, mMinute, false);
timePickerDialog.show();
}
}
I need to set the Date of 'DatePickerFragmenet' for a custom date (not today). such as set the 'DatePickerFragment' onCreate() to the mentioned above final int y, m, d values that from 'dateEditText'. And also I need to set the custom 'time' to the 'TimePickerDialog' such as 'DatePickerFragment'.
There is one function in DatePickerDialog to set custom date(updateDate(year_, month_, day_))
According to your code you need to make changes in your DatePickerFragment
in onCreateDialog of DatePickerFragment where you are getting date, month and year from calendar, instead of getting that from Calendar provide your custom dates.
Updated class is below
public class DatePickerFragment extends DialogFragment
implements DatePickerDialog.OnDateSetListener {
private onDatePickerListener mListener;
private boolean future;
int day_;
int month_;
int year_;
private DatePickerDialog datePickerDialog;
public DatePickerFragment() {
}
#Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current date as the default date in the picker
// final Calendar c = Calendar.getInstance();
// int year = c.get(Calendar.YEAR);
// int month = c.get(Calendar.MONTH);
// Log.d("DATE_PICKER", " CURRENT_MONTH " + month);
// int day = c.get(Calendar.DAY_OF_MONTH);
datePickerDialog = new DatePickerDialog(getActivity(), R.style.AppTheme, this, year_, month_, day_);
if (isFuture() == false) {
datePickerDialog.getDatePicker().setMaxDate(System.currentTimeMillis());
}
// datePickerDialog.updateDate(year_, month_, day_);
// Create a new instance of DatePickerDialog and return it
return datePickerDialog;
}
public void onDateSet(DatePicker view, int year, int month, int day) {
// Do something with the date chosen by the user
callListener(year, month, day);
}
public DialogFragment setCallbackListener(onDatePickerListener listener) {
mListener = listener;
return null;
}
private void callListener(int year, int month, int day) {
if (mListener != null) mListener.onDataSet(year, month, day);
}
public boolean isFuture() {
return future;
}
public void setFuture(boolean future) {
this.future = future;
}
public interface onDatePickerListener {
void onDataSet(int year, int month, int day);
}
}
In your activity, you need to provide custom date.
Updated Activity is below, you can add your custom date.
public class AddInterestedKarmaActivity extends AppCompatActivity {
DatePickerFragment datePickerDialog;
EditText dateEdittext;
String customDate = "12/12/2007"; //dd/mm/yy
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_interested_karma);
dateEdittext = (EditText) findViewById(R.id.date_edit);
// setDate(dateEditText);
datePickerDialog = new DatePickerFragment();
datePickerDialog.day_ = getDay();
datePickerDialog.month_ = getMonth();
datePickerDialog.year_ = getYear();
datePickerDialog.setCallbackListener(new DatePickerFragment.onDatePickerListener() {
#Override
public void onDataSet(int year, int month, int day) {
month = month + 1;
dateEdittext.setText(day + "/" + month + "/" + year);
}
}
);
datePickerDialog.show(getSupportFragmentManager(), "datePicker");
}
private int getYear() {
return Integer.parseInt(changeDateFormat(customDate, "MM/dd/yyyy", "YYYY"));
}
private int getMonth() {
return Integer.parseInt(changeDateFormat(customDate, "MM/dd/yyyy", "MM")) - 1; //substract one from month because month gets start from 0 in Calendar.
}
private int getDay() {
return Integer.parseInt(changeDateFormat(customDate, "MM/dd/yyyy", "dd"));
}
public String changeDateFormat(String dateString, String sourceDateFormat, String targetDateFormat) {
if (dateString == null || dateString.isEmpty())
return "";
SimpleDateFormat inputDateFromat = new SimpleDateFormat(sourceDateFormat, Locale.US);
Date date = new Date();
try {
date = inputDateFromat.parse(dateString);
} catch (ParseException e) {
e.printStackTrace();
}
SimpleDateFormat outputDateFormat = new SimpleDateFormat(targetDateFormat, Locale.US);
return outputDateFormat.format(date);
}
}

datepicker in android need to check weekend

I am doing datepicker. I am facing some challenges. I am checking wheather selected date is weekend or not. If it is weekend then it should give current date only. Now I don't know where should I put condition in this program and how to get the day of the week and against which thing I should check.
Please, help me.
// TimePickerDialog.OnTimeSetListener
{
//Declaration for class
ButtonViews views;
dpListener dpListenerView;
// Declartion for member vairables
int day, month, x_year;
int hour;
int minute;
Calendar calendar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
views = new ButtonViews();
dpListenerView = new dpListener();
//ButtonListener
views.button_date.setOnClickListener(this);
views.button_time.setOnClickListener(this);
//
// pick up the default date using Calender class
calendar = GregorianCalendar.getInstance(TimeZone.getTimeZone("GMT"), Locale.getDefault());
curr_date();
hour = calendar.get(Calendar.HOUR_OF_DAY);
minute = calendar.get(Calendar.MINUTE);
setupDate(day, month, x_year);
setupTime(hour, minute);
}
public void curr_date(){
day = calendar.get(Calendar.DAY_OF_MONTH);
month = calendar.get(Calendar.MONTH);
x_year = calendar.get(Calendar.YEAR);
}
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.button_date:
showDatePickerDialog();
break;
case R.id.button_time:
/* showTimePickerDialog();*/
break;
}
}
private void setupTime(int hours, int minutes) {
views.button_time.setText(hours + ":" + minutes);
}
private void setupDate(int day, int month, int year) {
SimpleDateFormat sdf = new SimpleDateFormat("dd-mm-yyyy");
String strMonth = ((month + 1) <= 9) ? ("0" + (month + 1)) : String.valueOf(month + 1);
views.button_date.setText(String.valueOf(day) + "/" + strMonth + "/" + String.valueOf(year));
String strDate = String.valueOf(day) + "/" + strMonth + "/" + String.valueOf(year);
Date d = null;
try {
d = (Date) sdf.parse(strDate);
} catch (ParseException e) {
e.printStackTrace();
}
calendar.setTime(d);
int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
if(dayOfWeek == 7 || dayOfWeek == 1) {
Toast.makeText(DateTimePickerActivity.this,"You have chosen weekend",Toast.LENGTH_SHORT);
}
}
private void showDatePickerDialog() {
DatePickerDialog datepickerdialog = new DatePickerDialog
(
this,
dpListenerView,
/* new DatePickerDialog.OnDateSetListener() {
#Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
} },*/
//this,
x_year,
month,
day
);
datepickerdialog.show();
}
class ButtonViews {
Button button_time;
Button button_date;
public ButtonViews() {
button_date = (Button) findViewById(R.id.button_date);
button_time = (Button) findViewById(R.id.button_time);
}
}
class dpListener implements OnDateSetListener {
#Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
setupDate(dayOfMonth, monthOfYear, year);
/* if(dayOfWeek == 7 || dayOfWeek == 1) {*/
// as your requirement: you should display message they can not select the weekend" here
// then you set the value in datepickerdialog by current date
// Toast.makeText(DateTimePickerActivity.this
// , "You have selected weekend ", Toast.LENGTH_SHORT).show();
// }
}
}
}

Add ID in Java file

I have created datePicker dialog in Java file. This is a code:
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current date as the default date in the picker
final Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);
//return new DatePickerDialog(getActivity(), (EditSessionActivity)getActivity(), year, month, day);
// Create a new instance of DatePickerDialog and return it
return new DatePickerDialog(getActivity(), this, year, month, day);
}
public void onDateSet(DatePicker view, int year, int month, int day) {
mDateDisplay .setText(String.valueOf(day) + "/"
+ String.valueOf(month + 1) + "/" + String.valueOf(year));
// set selected date into datepicker also
}
}
I want to add ID to my DatePicker. How can I do it from Java file.
Check it:
static final int DATE_DIALOG_ID = 999;
showDialog(DATE_DIALOG_ID);
override the following:
protected Dialog onCreateDialog(int id) {
Calendar c = Calendar.getInstance();
int cyear = c.get(Calendar.YEAR);
int cmonth = c.get(Calendar.MONTH);
int cday = c.get(Calendar.DAY_OF_MONTH);
return new DatePickerDialog(this, mDateSetListener, cyear, cmonth, cday);
}
Also I need a Listner:
private DatePickerDialog.OnDateSetListener datePickerListener
= new DatePickerDialog.OnDateSetListener() {
// when dialog box is closed, below method will be called.
public void onDateSet(DatePicker view, int selectedYear,
int selectedMonth, int selectedDay) {
year = selectedYear;
month = selectedMonth;
day = selectedDay;
//set selected date into textview
tvDisplayDate.setText(new StringBuilder().append(month + 1)
.append("-").append(day).append("-").append(year)
.append(" "));
// set selected date into datepicker also
dpResult.init(year, month, day, null);
}
};
Its always good to take a look at android API reference. Take a look at this and this
Anyway as an answer you can do the following
DatePicker picker=datePickerDialog.getDatePicker();
picker.setId("picker");

Categories