Android 向后兼容的setOnDateSetListener

Android 向后兼容的setOnDateSetListener,android,backwards-compatibility,datepickerdialog,Android,Backwards Compatibility,Datepickerdialog,我试图在片段中使用DatePickerDialog并为其设置OnDateSetListener,但是当我尝试使用setOnDateSetListener方法时,我得到一个编译时警告,比如调用需要API级别24(当前最小值为16)。 是否有其他方法可以接收此回调? 我的应用程序的最小SDK为16,最大SDK为26 这是我的密码: DatePickerDialog.Builder builder = new DatePickerDialog.Builder(getContext()); builde

我试图在
片段中使用
DatePickerDialog
并为其设置
OnDateSetListener
,但是当我尝试使用
setOnDateSetListener
方法时,我得到一个编译时警告,比如调用需要API级别24(当前最小值为16)。 是否有其他方法可以接收此回调? 我的应用程序的最小SDK为16,最大SDK为26

这是我的密码:

DatePickerDialog.Builder builder = new DatePickerDialog.Builder(getContext());
builder.setTitle(R.string.pick_date);
builder.setNegativeButton(R.string.cancel, null);
builder.setPositiveButton(R.string.ok, this);
DatePickerDialog dialogue = (DatePickerDialog) builder.create();
dialogue.setOnDateSetListener(this); // This is where I get the error
dialogue.show();

将此构造函数用于DatePickerDialog

DatePickerDialog(@NonNull Context context, @Nullable OnDateSetListener listener, int year, int month, int dayOfMonth)
DatePickerDialog(上下文)
构造函数添加到API级别24中

如果要使其向后兼容,请使用API级别1中添加的:

DatePickerDialog (Context context, 
                DatePickerDialog.OnDateSetListener listener, 
                int year, 
                int month, 
                int dayOfMonth)