question

Jon R. Helms avatar image
Jon R. Helms asked

Dialog & Back Button

I have 2 problems with the PIN dialog. 1, I haven't figured out how to implement the new password entry that uses the D-pad on the remote. But, bigger issue: I have a pin dialog and it works fine when you enter and if you cancel, but the back button just closes the dialog without firing the cancel event. How can I make the back button on the remote fire the cancel event on the dialog box?
fire tv
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Nick Gardner avatar image
Nick Gardner answered
Hi, Could you confirm what kind of pin dialog this is and what you are trying to do with it? I'm not sure what cancel event is supposed to be thrown here. Thanks, Nick
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Jon R. Helms avatar image
Jon R. Helms answered
It is an AlertDialog, I really want to get to the new dialog I've seen on the Amazon stuff, but haven't figured that out yet, and that is only applicable with the FireTV anyway. Here is my code: [code] AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setTitle("PIN Required"); alert.setMessage("Please enter your PIN to view restricted content."); dialoginput = new EditText(this); dialoginput.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_TEXT_VARIATION_PASSWORD); dialoginput.setTransformationMethod(PasswordTransformationMethod.getInstance()); alert.setView(dialoginput); alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { try { String PIN = dialoginput.getText().toString(); ResultSet result = ResultSet.LoadFromService(Watch.this, "Verify_PIN", PIN); if (Boolean.parseBoolean(result.Results.toString())) { ValidPINEntered(); } else { AlertDialog alertDialog = new AlertDialog.Builder(Watch.this).create(); alertDialog.setTitle("Invalid PIN Entered"); alertDialog.setMessage("Invalid PIN Entered, please try again."); alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, "Ok", new OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.cancel(); finish(); } }); alertDialog.show(); } } catch (Exception ex) { main.MessageBox(Watch.this, "Watch.PIN.onOKClick", ex); } } }); alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { finish(); } }); alert.show(); [/code]
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Jon R. Helms avatar image
Jon R. Helms answered
Just in case anyone else has this problem I had to add an onKeyListener to the alert dialog and then you can handle that the same as you would the cancel button in the dialog. [code] alert.setOnKeyListener(new DialogInterface.OnKeyListener() { @Override public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { dialog.cancel(); return true; } return false; } }); [/code]
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Nick Gardner avatar image
Nick Gardner answered
Thanks for sharing, hopefully will be able to help other developers in the future. -Nick
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.