This shows you the differences between two versions of the page.
sample_code:custom_dialog [2015/03/03 15:40] octazid created |
sample_code:custom_dialog [2015/08/20 12:55] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | =====Custom Yes-No-Dialog===== | ||
- | (Sample posted by Chris Hopkins in the DroidScrip Google Group)\\ \\ | ||
- | If you want to show a popup window on exit, you could use a custom Dialog.\\ For example, this is a small app that pops up a custom dialog when the back button is pressed\\ | ||
- | <code javascript custom_yes_no_dialog.js> | ||
- | //Called after application is started. | ||
- | function OnStart() | ||
- | { | ||
- | app.EnableBackKey( false ); | ||
- | app.ShowPopup( "Touch the Back Buttom" | ||
- | } | ||
- | |||
- | function OnBack() | ||
- | { | ||
- | //Create dialog window. | ||
- | dlgExit = app.CreateDialog( " | ||
- | |||
- | //Create a layout for dialog. | ||
- | layDlg = app.CreateLayout( " | ||
- | layDlg.SetPadding( 0.02, 0.02, 0.02, 0.02 ); | ||
- | dlgExit.AddLayout( layDlg ); | ||
- | |||
- | var btnYes = app.CreateButton(" | ||
- | btnYes.SetTextSize( 24 ); | ||
- | btnYes.SetOnTouch( btnYes_OnTouch ); | ||
- | layDlg.AddChild( btnYes ); | ||
- | |||
- | var btnNo = app.CreateButton(" | ||
- | btnNo.SetOnTouch( btnNo_OnTouch ); | ||
- | btnNo.SetTextSize( 24 ); | ||
- | layDlg.AddChild( btnNo ); | ||
- | |||
- | //Show dialog. | ||
- | dlgExit.Show(); | ||
- | } | ||
- | |||
- | function btnYes_OnTouch() | ||
- | { | ||
- | dlgExit.Dismiss(); | ||
- | app.Exit(); | ||
- | } | ||
- | |||
- | function btnNo_OnTouch() | ||
- | { | ||
- | dlgExit.Dismiss(); | ||
- | } | ||
- | </ |