This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
built_in:lists [2014/09/17 18:55] stevegarman created |
built_in:lists [2019/08/31 16:10] stevegarman Remove obsolete extra line |
||
---|---|---|---|
Line 1: | Line 1: | ||
====== Lists ====== | ====== Lists ====== | ||
- | ===== Create | + | |
- | Create List objects using the CreateList method of the app object: | + | // |
+ | |||
+ | ===== Description | ||
+ | Create List objects using the **CreateList** method of the **[[built_in: | ||
< | < | ||
- | Use the SetOnTouch and SetOnLongTouch methods of the List object to set the name of a function you want to be called when a list item is selected. The selected item is passed into your OnTouch callback function as a parameter every time an item is selected or long touched. | + | Use the **SetOnTouch** and **SetOnLongTouch** methods of the List object to set the name of a function you want to be called when a list item is selected. The selected item is passed into your OnTouch callback function as a parameter every time an item is selected or long touched. |
+ | |||
+ | ====Example - Simple==== | ||
+ | <code javascript> | ||
+ | function OnStart() | ||
+ | { | ||
+ | lay = app.CreateLayout( " | ||
+ | |||
+ | lst = app.CreateList( " | ||
+ | lst.SetOnTouch( lst_OnTouch ); | ||
+ | lst.SetOnLongTouch( lst_OnLongTouch ); | ||
+ | lay.AddChild( lst ); | ||
+ | |||
+ | app.AddLayout( lay ); | ||
+ | } | ||
+ | |||
+ | function lst_OnTouch( item ) | ||
+ | { | ||
+ | app.ShowPopup( "Item = " + item, " | ||
+ | } | ||
+ | function lst_OnLongTouch( item ) | ||
+ | { | ||
+ | app.ShowPopup( "Long Touch = " + item, " | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | You can change the look of a List using the **SetBackColor** and **SetTextColor** functions on the list object. You can also set a background image/ | ||
+ | |||
+ | ====Example - Gray on white==== | ||
+ | <code javascript> | ||
+ | function OnStart() | ||
+ | { | ||
+ | lay = app.CreateLayout( " | ||
+ | |||
+ | lst = app.CreateList( " | ||
+ | lst.SetTextColor( "# | ||
+ | lst.SetBackColor( "# | ||
+ | lst.SetOnTouch( lst_OnTouch ); | ||
+ | lay.AddChild( lst ); | ||
+ | |||
+ | app.AddLayout( lay ); | ||
+ | } | ||
+ | |||
+ | function lst_OnTouch( item ) | ||
+ | { | ||
+ | app.ShowPopup( " | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | The List object also supports **multi-line** list items and can show certain types of **icon**. Multi-line items are created by dividing each list item up using the ':' | ||
+ | |||
+ | You can have one icon and one or two lines of text using the following formats: | ||
+ | |||
+ | * title : icon | ||
+ | * title : body : icon | ||
+ | |||
+ | The available icons types are displayed using the following key words: | ||
+ | |||
+ | * " | ||
+ | * " | ||
+ | * " | ||
+ | * " | ||
+ | * " | ||
+ | * " | ||
+ | * " | ||
+ | * " | ||
+ | |||
+ | You can also use resource images or images from your sdcard instead of the keywords, for example:- " | ||
+ | |||
+ | |||
+ | ====Example - Title + Icon==== | ||
+ | <code javascript> | ||
+ | function OnStart() | ||
+ | { | ||
+ | lay = app.CreateLayout( " | ||
+ | |||
+ | var data = " | ||
+ | lst = app.CreateList( data, 0.8, 0.4 ); | ||
+ | lst.SetOnTouch( lst_OnTouch ); | ||
+ | lay.AddChild( lst ); | ||
+ | |||
+ | app.AddLayout( lay ); | ||
+ | } | ||
+ | |||
+ | function lst_OnTouch( item ) | ||
+ | { | ||
+ | app.ShowPopup( " | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ====Example - Title + Body==== | ||
+ | <code javascript> | ||
+ | function OnStart() | ||
+ | { | ||
+ | lay = app.CreateLayout( " | ||
+ | |||
+ | var data = "The Hobbit: | ||
+ | data += ", | ||
+ | lst = app.CreateList( data, 0.8, 0.4 ); | ||
+ | lst.SetOnTouch( lst_OnTouch ); | ||
+ | lay.AddChild( lst ); | ||
+ | |||
+ | app.AddLayout( lay ); | ||
+ | } | ||
+ | |||
+ | function lst_OnTouch( item ) | ||
+ | { | ||
+ | app.ShowPopup( " | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | You can also create lists items that look like **buttons** by using one of the following options: | ||
+ | |||
+ | * " | ||
+ | * " | ||
+ | * " | ||
+ | |||
+ | ====Example - Orange Buttons==== | ||
+ | <code javascript> | ||
+ | function OnStart() | ||
+ | { | ||
+ | lay = app.CreateLayout( " | ||
+ | |||
+ | var data = " | ||
+ | lst = app.CreateList( data, 0.8, 0.8, " | ||
+ | lst.SetBackColor( "# | ||
+ | lst.SetPadding( 0.1, 0.1, 0.1, 0.1 ); | ||
+ | lst.SetOnTouch( lst_OnTouch ); | ||
+ | lay.AddChild( lst ); | ||
+ | |||
+ | app.AddLayout( lay ); | ||
+ | } | ||
+ | |||
+ | function lst_OnTouch( item ) | ||
+ | { | ||
+ | app.ShowPopup( " | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Or create lists with **Gradient** backgrounds like this: | ||
+ | |||
+ | ====Example - Gradient Background==== | ||
+ | <code javascript> | ||
+ | function OnStart() | ||
+ | { | ||
+ | lay = app.CreateLayout( " | ||
+ | |||
+ | var data = ""; | ||
+ | for( var i=1; i<=30; i++) | ||
+ | { | ||
+ | if( i>1 ) data += ","; | ||
+ | data += "Item " | ||
+ | } | ||
+ | lst = app.CreateList( data, 1, 1, " | ||
+ | lst.SetTextColor1( "# | ||
+ | lst.SetTextColor2( "# | ||
+ | lst.SetTextMargins( 0.04, 0, 0, 0 ); | ||
+ | lst.SetOnTouch( lst_OnTouch ); | ||
+ | lay.AddChild( lst ); | ||
+ | |||
+ | app.AddLayout( lay ); | ||
+ | } | ||
+ | |||
+ | function lst_OnTouch( item ) | ||
+ | { | ||
+ | app.ShowPopup( " | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | |||
+ | ====Example - HTML Font Color==== | ||
+ | <code javascript> | ||
+ | function OnStart() | ||
+ | { | ||
+ | // | ||
+ | lay = app.CreateLayout( " | ||
+ | |||
+ | // | ||
+ | var data = | ||
+ | "< | ||
+ | "< | ||
+ | "< | ||
+ | lst = app.CreateList( data, | ||
+ | lay.AddChild( lst ); | ||
+ | |||
+ | // | ||
+ | app.AddLayout( lay ); | ||
+ | } | ||
+ | </ | ||
+ | ---- | ||
===== Methods ===== | ===== Methods ===== | ||
- | ^Method ^Description ^ | + | Some controls use the same methods.\\ |
- | |lst.GetHeight| | | + | For examples of the **[[same methods]]** look here. |
- | |lst.GetList| | | + | ^ Method |
- | |lst.GetVisibility| | | + | | List.AddItem( title, |
- | |lst.GetWidth| | | + | | List.GetAbsHeight() |
- | |lst.Release| | | + | | List.GetAbsWidth() |
- | |lst.ScrollToItem| | | + | | List.GetHeight() | |
- | |lst.SelectItem| | | + | | List.GetItemByIndex( index ) |
- | |lst.SetBackColor| | | + | | List.GetLength() |
- | |lst.SetBackGradient| | | + | | List.GetList( delimeter ) |
- | |lst.SetBackGradientRadial| | | + | | List.GetPosition() |
- | |lst.SetBackground| | | + | | List.GetTextSize( mode ) |
- | |lst.SetHiTextColor1| | | + | | List.GetType() |
- | |lst.SetHiTextColor2| | | + | | List.GetVisibility() | |
- | |lst.SetList| | | + | | List.GetWidth() | | |
- | |lst.SetMargins| | | + | | List.InsertItem(index, |
- | |lst.SetOnLongTouch| | | + | | List.RemoveAll() |
- | |lst.SetOnTouch| | | + | | List.RemoveItem( title ) | |
- | |lst.SetPadding| | | + | | List.RemoveItemByIndex( index ) |
- | |lst.SetPosition| | | + | | List.ScrollToItem( name,body ) | |
- | |lst.SetSize| | | + | | List.ScrollToItemByIndex( index ) | | |
- | |lst.SetTextColor| | | + | | List.SelectItem( title, |
- | |lst.SetTextColor1| | | + | | List.SelectItemByIndex( index, |
- | |lst.SetTextColor2| | | + | | List.SetBackColor( colorCode ) | |
- | |lst.SetTextMargins| | | + | | List.SetBackGradient( color1, |
- | |lst.SetTextSize| | | + | | List.SetBackGradientRadial( x, |
- | |lst.SetVisibility! ! | + | | List.SetBackground( imagefile, |
+ | | List.SetDivider( height, | ||
+ | | List.SetEllipsize( mode ) | | | ||
+ | | List.SetEllipsize1( mode ) | ||
+ | | List.SetEllipsize2( mode ) | ||
+ | | List.SetFontFile( file ) | ||
+ | | List.SetHiTextColor1( colorCode ) | ||
+ | | List.SetHiTextColor2( colorCode ) | ||
+ | | List.SetItem( title, | ||
+ | | List.SetItemByIndex( index, | ||
+ | | List.SetList( list, | ||
+ | | List.SetMargins( left, | ||
+ | | List.SetOnLongTouch( callback ) | ||
+ | | List.SetOnTouch( callback ) | ||
+ | | List.SetPadding( left, | ||
+ | | List.SetPosition( left, | ||
+ | | List.SetScale( x,y ) | ||
+ | | List.SetSize( width, | ||
+ | | List.SetTextColor( colorCode ) | | ||
+ | | List.SetTextColor1( colorCode ) | ||
+ | | List.SetTextColor2( colorCode ) | ||
+ | | List.SetTextMargins( left, | ||
+ | | List.SetTextShadow( radius, | ||
+ | | List.SetTextShadow1( radius, | ||
+ | | List.SetTextShadow2( radius, | ||
+ | | List.SetTextSize( size,mode ) | ||
+ | | List.SetVisibility( ShowHide ) | ||
+ | |||
+ | ===== Available Options ===== | ||
+ | |||
+ | ^ Option | ||
+ | | AlumButton | ||
+ | | FontAwesome | ||
+ | | GreenButton | ||
+ | | Html | Use this option to display html formated code | | ||
+ | | OrangeButton | ||
+ | | WhiteGrad | ||
+ | |||
+ | ===== Sample callbacks ===== | ||
+ | |||
+ | <code javascript> | ||
+ | function lst_OnTouch( title, body, type, index ) | ||
+ | { | ||
+ | app.ShowPopup( "id: " + title + " nick: " + body ); | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | <code javascript> | ||
+ | function lst_OnLongTouch( title, body, type, index ) | ||
+ | { | ||
+ | app.ShowPopup( "id: " + title + " nick: " + body ); | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | <code javascript> | ||
+ | function lst_OnTouch( title, body, type, index ) | ||
+ | { | ||
+ | //Shows the index of the touched item | ||
+ | app.ShowPopup(index) | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | <code javascript> | ||
+ | function lst_OnTouch( item ) | ||
+ | { | ||
+ | //Shows the touched item | ||
+ | app.ShowPopup(item) | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ---- |