var inbox, txt; function OnStart() { var lay = app.CreateLayout( "linear", "VCenter,FillXY" ); txt = app.CreateText( "Hello" ); txt.SetTextSize( 32 ); lay.AddChild( txt ); var ask = app.CreateButton( "Ask for some text" ); ask.SetOnTouch( ask_OnTouch ); lay.AddChild( ask ); app.AddLayout( lay ); inbox = inputBox("What is your name?", gotInput,"Name",0.9); } function ask_OnTouch() { //inbox.SetText(""); //inbox.Show(); inbox.ShowWithKeyboard(); } function gotInput() { txt.SetText( this.GetText() ); } // This function returns an input dialog // title (optional) dialog title, suppressed if empty // okCallback (required) function called when Ok touched // hint (optional) empty string displays no hint // width (optional) 0 to 1 used when creating TextBox function inputBox(title, okCallback, hint, width) { var options = "NoCancel" title = title || ""; hint = hint || "Your text"; //suppress title line if no title - pass " " to override if( title==="") options += ",NoTitle"; // create dialog var dlg = app.CreateDialog( title,options ); var lay = app.CreateLayout( "Linear", "" ); dlg.AddLayout( lay ); // add controls var edt = app.CreateTextEdit( "", width ); edt.SetHint( hint ); lay.AddChild( edt ); var layBtn = app.CreateLayout( "Linear", "Horizontal" ); lay.AddChild( layBtn ); var btnCancel = app.CreateButton( "Cancel",-1,-1,"custom" ); btnCancel.SetOnTouch( function(){dlg.Dismiss();} ); layBtn.AddChild( btnCancel ); var btnOk = app.CreateButton( "Ok",-1,-1,"custom" ); layBtn.AddChild( btnOk ); btnOk.SetOnTouch( function(){okCallback.call(edt);dlg.Dismiss()} ); // public functions dlg.ShowKeyboard = function( ) {edt.Focus();app.ShowKeyboard( edt );} dlg.SetText = function(txt){edt.SetText(txt);} dlg.ShowWithKeyboard=function() {setTimeout(dlg.ShowKeyboard, 100);dlg.Show();} // return dlg }