- downloadFileNameTextView.setOnKeyListener(new View.OnKeyListener() {
- @Override
- public boolean onKey (View v, int keyCode, KeyEvent event) {
- // If the event is an `ACTION_DOWN` on the `enter` key, initiate the download.
- if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
- // trigger `onDownloadFile()` and return the `DialogFragment` and the URL to the parent activity.
- downloadFileListener.onDownloadFile(DownloadFileDialog.this, downloadUrl);
- // Manually dismiss `alertDialog`.
- alertDialog.dismiss();
- // Consume the event.
- return true;
- } else { // If any other key was pressed, do not consume the event.
- return false;
- }
+ downloadFileNameTextView.setOnKeyListener((View v, int keyCode, KeyEvent event) -> {
+ // If the event is an `ACTION_DOWN` on the `enter` key, initiate the download.
+ if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
+ // trigger `onDownloadFile()` and return the `DialogFragment` and the URL to the parent activity.
+ downloadFileListener.onDownloadFile(DownloadFileDialog.this, downloadUrl);
+
+ // Manually dismiss the alert dialog.
+ alertDialog.dismiss();
+
+ // Consume the event.
+ return true;
+ } else { // If any other key was pressed, do not consume the event.
+ return false;