This shows you the differences between two versions of the page.
Both sides previous revision Previous revision | |||
sample_code:textedit_search [2015/04/01 12:26] stevegarman |
sample_code:textedit_search [2015/08/05 06:40] octazid Add simple Sample |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Simple Custom Search Bar ====== | ||
+ | |||
+ | A simple custom search bar could be made up from a TextEdit control and a search button control, contained within a horizontal Linear Layout. The code below is a very simple quick implementation. | ||
+ | |||
+ | <code javascript search.js> | ||
+ | var txtSize = 22; | ||
+ | |||
+ | //Called when application is started. | ||
+ | function OnStart() | ||
+ | { | ||
+ | lay = app.CreateLayout( " | ||
+ | lay.SetBackground( "/ | ||
+ | |||
+ | //Create a layout to hold the search controls | ||
+ | laySearch = app.CreateLayout( " | ||
+ | laySearch.SetBackColor( "# | ||
+ | laySearch.SetPadding( 0, 0.01, 0, 0.01 ); | ||
+ | |||
+ | //Create a TextEdit control for entering search text | ||
+ | txeSearch = app.CreateTextEdit( "", | ||
+ | txeSearch.SetTextSize( txtSize ); | ||
+ | |||
+ | //Create a search button | ||
+ | btnSearch = app.CreateText( " | ||
+ | btnSearch.SetTextSize( txtSize ); | ||
+ | btnSearch.SetOnTouch( btnSearch_OnTouch ); | ||
+ | |||
+ | laySearch.AddChild( txeSearch ); | ||
+ | laySearch.AddChild( btnSearch ); | ||
+ | lay.AddChild( laySearch ); | ||
+ | |||
+ | //Add layout to app. | ||
+ | app.AddLayout( lay ); | ||
+ | } | ||
+ | |||
+ | //Called when the search button is pressed | ||
+ | function btnSearch_OnTouch( ev ) | ||
+ | { | ||
+ | if( ev.action==" | ||
+ | { | ||
+ | this.SetTextSize( txtSize-4 ); | ||
+ | } | ||
+ | else if( ev.action==" | ||
+ | { | ||
+ | this.SetTextSize( txtSize ); | ||
+ | |||
+ | var searchText = txeSearch.GetText(); | ||
+ | app.ShowPopup( " | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | //(Sample posted by Chris Hopkin in the Droidscript Forum)// | ||
+ | ---- | ||
+ | |||
+ | |||
====== TextEdit Search ====== | ====== TextEdit Search ====== | ||
This function is designed to search for a string in a textEdit. | This function is designed to search for a string in a textEdit. |