I am writing way to add and use date Picker Material design library to our project.
First of all we need to add library to our build.gradle file
dependencies {
compile 'com.wdullaer:materialdatetimepicker:1.5.4'
}
Then we need to implements OnDateSetListener to our Activity or Fragment and after it we need to
override its method onDateSet() that will invoke when you choose the date.
@Override
public void onDateSet(DatePickerDialog view, int yr, int mtnYr, int dayMonth) {
String date = "dayMonth +"/"+( mtnYr +1)+"/"+yr;
textViewDate.setText(date);
}
To open date Picker we need to implement this:
Calendar calendar = Calendar.getInstance();
DatePickerDialog datePicker = DatePickerDialog.newInstance(
MyActivity.this,
calendar.get(Calendar.YEAR),
calendar.get(Calendar.MONTH),
calendar.get(Calendar.DAY_OF_MONTH)
);
datePicker.show(getFragmentManager(), "datepicker");
1 Comment(s)