User Tools

Site Tools


Sidebar

Privacy Policy

News

Version 2.50 is out since Jan 1st 2022


Frequently Asked Questions


Namespaces

Note for contributors

If you wish to create a new page in the DroidScript wiki, please click on the most appropriate namespace above and follow the notes for contributors there.

Because of spam, it has been necessary to add a CAPTCHA to the registration form and the save option for editing pages. You will not need to prove you are human if you are logged in, so please register.

Please feel free to improve any existing page, as well as adding new pages to increase the sum of public knowledge about DroidScript.

Formatting Syntax

sample_code:dialogbox

Sample dialog box

This code was pinched from Dave Smart to check out the code blocks on the wiki.

dialogList.js
//This demos creating dialog boxes.  You can add
//any type of control to a dialog box.  Here we
//just adding a list control.
 
//Called when application is started.
function OnStart()
{
	//Create a layout with objects vertically centered.
	lay = app.CreateLayout( "linear", "VCenter,FillXY" );	
 
	//Create a button to launch the dialog.
	btn = app.CreateButton( "Show Dialog Box", 0.6, 0.1 );
	btn.SetOnTouch( btn_OnTouch );
	lay.AddChild( btn );
 
	//Add layout to app.	
	app.AddLayout( lay );
}
 
//Called when user touches our button.
function btn_OnTouch()
{
    //Create dialog window.
    dlgTxt = app.CreateDialog( "Choose a Fruit" );
 
    //Create a layout for dialog.
    layDlg = app.CreateLayout( "linear", "vertical,fillxy,left" );
    layDlg.SetPadding( 0.02, 0, 0.02, 0.02 );
    dlgTxt.AddLayout( layDlg );
 
    //Create a list control.
    var list = "Apples,Oranges,Bananas,Cheese,Milk,Eggs,Flour";
    lstDlg = app.CreateList( list, 0.8, 0.3 );
    lstDlg.SetTextSize( 22 );
    lstDlg.SetTextColor( "#dddddd" );
    lstDlg.SetOnTouch( lst_OnTouch );
    layDlg.AddChild( lstDlg );
 
    //Show dialog.
    dlgTxt.Show();
}
 
//Handle list item selection.
function lst_OnTouch( item )
{
    //Hide the dialog window.
    dlgTxt.Hide();
 
    //Show which fruit the user chose.
    app.ShowPopup( "You chose " + item, "Short" );
}
sample_code/dialogbox.txt · Last modified: 2014/09/21 17:22 (external edit)