Example usage for android.app TimePickerDialog setOnKeyListener

List of usage examples for android.app TimePickerDialog setOnKeyListener

Introduction

In this page you can find the example usage for android.app TimePickerDialog setOnKeyListener.

Prototype

public void setOnKeyListener(@Nullable OnKeyListener onKeyListener) 

Source Link

Document

Sets the callback that will be called if a key is dispatched to the dialog.

Usage

From source file:com.simplaapliko.trips.presentation.fragment.SelectTimeDialog.java

@NonNull
@Override/* w  w  w .  j ava  2 s.  co  m*/
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final TimePickerDialog pickerDialog = new TimePickerDialog(getActivity(), this,
            mCalendar.get(Calendar.HOUR_OF_DAY), mCalendar.get(Calendar.MINUTE),
            DateFormat.is24HourFormat(getActivity()));

    pickerDialog.setOnKeyListener((dialog, keyCode, event) -> {
        switch (keyCode) {
        case KeyEvent.KEYCODE_BACK:
            dialog.cancel();
            dialog.dismiss();
            return true;
        default:
            return false;
        }
    });

    return pickerDialog;
}