var edt,fnd; //Called when application is started. function OnStart() {     //Create a layout with objects vertically centered.     var lay = app.CreateLayout( "linear", "VCenter,FillXY" );         var hlay = app.CreateLayout( "linear", "Horizontal,FillX" );     var btn = app.CreateButton("Find");     btn.SetOnTouch(doFind);     hlay.AddChild(btn);     fnd = app.CreateTextEdit("show");     fnd.SetHint("Find");     hlay.AddChild(fnd);     lay.AddChild(hlay);     //Create a text label and add it to layout.     var scrollEdit = app.CreateScroller( 1.0, 0.83, "" );     //Create a textedit and add it to layout.     edt = app.CreateTextEdit( "",1,-1,"Left,NoSpell" );     edt.SetText(app.ReadFile("/android_asset/app.js"))     //edt.SetBackColor("#ffcccccc");     //edt.SetTextColor("#ff333333");     scrollEdit.AddChild(edt);     lay.AddChild( scrollEdit);          //Add layout to app.         app.AddLayout( lay ); } function doFind() {    app.HideKeyboard();    var findstring = fnd.GetText();    findtext(edt,findstring) } function findtext(thisedt,sought) //thisedt = textEdit to be searched. //sought = string to be searched for. {    //both toLowerCase for case-insensitive search    var lc = thisedt.GetText().toLowerCase();    sought = sought.toLowerCase();    //current cursor position is start for search    var curs = thisedt.GetCursorPos();    //only compare against the searchable range    lc = lc.slice(curs+1)    // try to find next occurence of sought    var pos = lc.search(sought);    if ( pos > -1)    {        //we found it       pos  = pos + curs +1       thisedt.SetCursorPos(pos)       thisedt.SetSelection(pos, pos+sought.length);    }    else    {       //not found - go to start of text       //user can search again from there if required.       thisedt.SetCursorPos(0)    } }