Привет, я пытаюсь преобразовать этот код в Kotlin. но не может
Ide не может автоматически конвертировать
alertDialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
@Override
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
// Prevent dialog close on back press button
return keyCode == KeyEvent.KEYCODE_BACK;
}
});
Интерфейс
interface OnKeyListener {
/**
* Called when a key is dispatched to a dialog. This allows listeners to
* get a chance to respond before the dialog.
*
* @param dialog the dialog the key has been dispatched to
* @param keyCode the code for the physical key that was pressed
* @param event the KeyEvent object containing full information about
* the event
* @return {@code true} if the listener has consumed the event,
* {@code false} otherwise
*/
boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event);
}
Что я пробовал
dialog.setOnKeyListener(
DialogInterface.OnKeyListener { dialog, keyCode, event ->
}
)