Calendar calendar = Calendar.getInstance();
MaterialDatePicker.Builder<Long> builder = MaterialDatePicker.Builder.datePicker();
builder.setTitleText(R.string.title_pick_a_date);
if (dateDF == null) {
builder.setSelection(calendar.getInstance().getTimeInMillis());
} else {
String date = dateDF.toString();
calendar.setTime(dateDF);
builder.setSelection(calendar.getTimeInMillis());
}
MaterialDatePicker<Long> picker = builder.build();
picker.addOnPositiveButtonClickListener(new MaterialPickerOnPositiveButtonClickListener<Long>
() {
@Override
public void onPositiveButtonClick(Long selection) {
calendar.setTimeInMillis(selection);
calendar.setTimeZone(calendar.getTimeZone());
int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
int month = calendar.get(Calendar.MONTH);
int year = calendar.get(Calendar.YEAR);
String dateSF = dayOfMonth + "/" + (month + 1) + "/" + year;
calendar.set(year, month, dayOfMonth);
Date date = calendar.getTime();
String a = "a";
binding.layoutContentFeedFormulaDetails.tIeDate.setText(dateSF);
binding.layoutContentFeedFormulaDetails.tIeDate.setTag(calendar.getTime());
}
});
binding.layoutContentFeedFormulaDetails.btnDatePicker.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
picker.show(getSupportFragmentManager(), picker.toString());
}
});
Hi,
I am using android MaterialDatePicker in an android application I am building.
The above code works perfectly fine. However, say for example, I have set the date to 26/08/2018 and open the materialDatePicker dialog, the calendar is scrolled to the current date and not the set date. I want the calendar scrolled automatically to the set date when the dialog is opened. I frantically looked all over the internet and couldn't find an answer. Please help me!
Thank you very much.
Sorry! This is my first question here on Stack overflow. I hope I didn't break any of its guidelines.