Back

CreateList

Hello World
Content:
- Methods

If you want to display many dataset of the same structure you might consider using the List object.

lst = app.CreateList( list, width, height, options ) → app object: List

The List object supports multi-line list items and can show icons. Multi-line items are created by dividing each list item up using the “:” (colon) character. If you need to use a colon character in your item text then use this character sequence: “^c^”.
You can have one icon and some body text using the following formats:

“title”
“title:icon”
“title:body:icon”

Alternatively you can use the AddItem method which accepts title, body and icon as parameters to generically build up your list.

You can specify your own icon file for example “Img/MyIcon.png”, or one of the special built-in icons using the following key words: “audio”, “photo”, “video”, “folder”, “audiofolder”, “photofolder”, “videofolder” and “playlist”.

Example - Title + Icon

function OnStart()
{
    lay = app.CreateLayout( "Linear", "VCenter,FillXY" );

    var data = "Folder:folder,Audio:audio,Photo:photo,Video:video";
    lst = app.CreateList( data, 0.8, 0.4 );
    lst.SetOnTouch( lst_OnTouch );
    lay.AddChild( lst );


    app.AddLayout( lay );
}

function lst_OnTouch( title, body, type, index )
{
    app.ShowPopup( "Touched Item = " + title );
}
    Copy     Copy All       Run      

Example - Title + Body

function OnStart()
{
    lay = app.CreateLayout( "Linear", "VCenter,FillXY" );

    var data = "The Hobbit:Author^c^ J.R.R. Tolkien:null";
    data += ",Watership Down:Author^c^ Richard Adams:null";
    lst = app.CreateList( data, 0.8, 0.4 );
    lst.SetOnTouch( lst_OnTouch );
    lay.AddChild( lst );


    app.AddLayout( lay );
}

function lst_OnTouch( title, body, type, index )
{
    app.ShowPopup( "Touched Item = " + title );
}
    Copy     Copy All       Run      

You can use the SetOnTouch and SetOnLongTouch methods to define a function you want to be called when a list item is selected. The selected item title, body, type and index are passed into your OnTouch callback function as parameters.

Example - Simple

function OnStart()
{
    lay = app.CreateLayout( "Linear", "VCenter,FillXY" );

    lst = app.CreateList( "Fred,Bill,Jim", 0.8, 0.4 );
    lst.SetOnTouch( lst_OnTouch );
    lst.SetOnLongTouch( lst_OnLongTouch );
    lay.AddChild( lst );


    app.AddLayout( lay );
}

function lst_OnTouch( title, body, icon, index )
{
    app.ShowPopup( "Item = " + title + ", Index = " + index, "Short" );
}

function lst_OnLongTouch( title, body, icon, index )
{
    app.ShowPopup( "Long Touch Item = " + title + ", Index = " + index, "Short" );
}
    Copy     Copy All       Run      

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/pattern or background gradient for the List using the SetBackground and SetBackGradient functions.

Example - Gray on White

function OnStart()
{
    lay = app.CreateLayout( "Linear", "VCenter,FillXY" );

    lst = app.CreateList( "Fred,Bill,Jim", 0.8, 0.4 );
    lst.SetTextColor( "#ff666666" );
    lst.SetBackColor( "#ffffffff" );
    lst.SetOnTouch( lst_OnTouch );
    lay.AddChild( lst );


    app.AddLayout( lay );
}

function lst_OnTouch( title, body, type, index )
{
    app.ShowPopup( "Touched Item = " + title );
}
    Copy     Copy All       Run      

You can also create lists items that look like buttons by using one of the following options: “AlumButton”, “GreenButton”, “OrangeButton”.

Example - Orange Buttons

function OnStart()
{
    lay = app.CreateLayout( "Linear", "VCenter,FillXY" );

    var data = "Button 1,Button 2,Button 3,Button 4";
    lst = app.CreateList( data, 0.8, 0.8, "OrangeButton" );
    lst.SetBackColor( "#ffffff" );
    lst.SetPadding( 0.1, 0.1, 0.1, 0.1 );
    lst.SetOnTouch( lst_OnTouch );
    lay.AddChild( lst );


    app.AddLayout( lay );
}

function lst_OnTouch( title, body, type, index )
{
    app.ShowPopup( "Touched Item = " + title );
}
    Copy     Copy All       Run      

Or create lists with Gradient backgrounds like this:

Example - Gradient Background

function OnStart()
{
    lay = app.CreateLayout( "Linear", "VCenter,FillXY" );

    var data = "";
    for( var i = 1; i <= 30; i++ )
    {
        if( i > 1 ) data += ",";
        data += "Item " + i + ":Details for item " + i + ":null";
    }
    lst = app.CreateList( data, 1, 1, "WhiteGrad" );
    lst.SetTextColor1( "#ff555558");
    lst.SetTextColor2( "#ff555558" );
    lst.SetTextMargins( 0.04, 0, 0, 0 );
    lst.SetOnTouch( lst_OnTouch );
    lay.AddChild( lst );


    app.AddLayout( lay );
}

function lst_OnTouch( title, body, type, index )
{
    app.ShowPopup( "Touched Item = " + title );
}
    Copy     Copy All       Run      

Methods

The following methods are available on the List object:

Focus()
GetAbsHeight() → Number: integer
GetAbsWidth() → Number: integer
GetItem( title ) → Object: { title, body, image }
GetItemByIndex( index ) → Object: { title, body, image }
GetLength() → Number: integer
GetList( delim ) → List: of objects: [{ title, body, image }]
String: “title1[DELIM]title2[DELIM]...”
GetParent() → app object
GetPosition( options ) → Object: { left, top, right, bottom }
GetType() → String: “List”
GetVisibility() → String: “Show” or “Hide” or “Gone”
Gone()
Hide()
Method( name, types, p1, p2, p3, p4 ) → all types
SetScale( x, y )
Show()
Boolean
app object
Number
String
unknown
Number: angle in degrees (0..360)
Number: factor
Number: fraction (0..1)
Number: integer
Number: milliseconds
Number: -180..180
Number: -100..100
Number: 0..100
Number: 0..0.99 or 1..256
String:
  hexadecimal: “#rrggbb”, “#aarrggbb”
  colourName: “red”, “green”, ...
String: comma “,” separated
String: path to file ( “/absolute/...” or “relative/...” )
String: path to file or folder ( “/absolute/...” or “relative/...” )
String: comma “,” separated: bold or Expand, Menu, Horiz, “html”, “FontAwesome”, “monospace”, “Normal”, “WhiteGrad” or “BlackGrad” or “AlumButton” or “GreenButton” or “OrangeButton”, “NoSound”
String: “NewsPaper” or “Jelly” or “Flash” or “RubberBand” or “Swing” or “TaDa” or “Bounce” or “Fall” or “FallRotate” or
String: “px”
String: “screen”, “px”
String: “left-right” or “right-left” or “top-bottom” or “bottom-top” or “bl-tr” or “br-tl” or “tl-br” or “tr-bl”
String: “repeat”
String: “Add” or “Multiply” or “clear” or “darken” or “lighten” or “overlay” or “screen” or “xor” or “src_in” or “src_out” or “src_atop” or “src_over” or “dst_in” or “dst_out” or “dst_atop” or “dst_over”
String: comma “,” separated: “px” or “sp” or “dip” or “mm” or “pt”
String: “start” or “middle” or “end”
String: separated: “title” or “title:icon” or “title:body:icon”
String: “px” or “sp” or “dip” or “mm” or “pt”
String: “px” or “sp” or “dip” or “dp” or “mm” or “pt”
String: inner or outer
String: “px” or “dip” or “sp” or “mm” or “pt” or pl or ps
String: “Show” or “Hide” or “Gone”
String: “Linear.None” or “Quadratic.In/Out” or “Cubic.In/Out” or “Quartic.In/Out” or “Quintic.In/Out” or “Sinusoidal.In/Out” or “Exponential.In/Out” or “Circular.In/Out” or “Elastic.In/Out” or “Back.In/Out” or “Bounce.In/Out”
String
String: path to file ( “/absolute/...” or “relative/...” )
Object: { x, y, w, h, sw, sh, rot }
List: boolean,char,byte,short,int,long,float,double,String,CharSequence,...
function( type )
function( title, body, icon, index )
function()
lst.AddItem
Adds an entry to the list.
lst.AdjustColor
Adjust the visual color effect of the control by setting the Hue (by angle in degrees in a color circle), the saturation, brightness and contrast of the control.
lst.Animate
Animates the control.

There are
    “in”-Animations which are used to show objects from hidden state
    “out”-animations which are used to hide objects in visible state and
    “static”-animations which keep the visible state.
lst.ClearFocus
Removes the focus of the control so that the user no longer has immediate access to it.
lst.Focus
Set the focus to the control so that the user can interact with it immediately.
lst.GetAbsHeight
Get the absolute height of the control in pixels.
lst.GetAbsWidth
Get the absolute width of the control in pixels.
lst.GetHeight
Get the height of the control as screen height relative float or in pixels with the px option.
lst.GetItem
Returns item data of an item with a specific title.
lst.GetItemByIndex
Returns item data of an item on a specific index.
lst.GetLeft
Get the distance from the control to the left parent border as width relative float or in pixels with the px option.
lst.GetLength
Returns the amount of items in the lists.
lst.GetList
When passing no argument it returns the full list data as a list of objects. Otherwise it will return a string list instead.
lst.GetParent
Returns the parent control object where the object was added to - commonly a layout.
lst.GetPosition
Returns data about the position and size of the control.
If the screen option is given the position on the screen will be returned. Otherwise relative to the parent control.
The px options turns the relative values into pixels.
lst.GetTextSize
Returns the current size of the contained text. If the px option is given the size will be retured in pixels.
lst.GetTop
Get the distance from the control to the upper parent border as height relative float or in pixels with the px option.
lst.GetType
Returns the control class name.
lst.GetVisibility
Returns the current visibility state of the control. The Values are:
Show: visible
Hide: invisible but still consuming space
Gone: invisible and not consuming space
lst.GetWidth
Get the width of the control as screen width relative float or in pixels with the px option.
lst.Gone
Hides the control without consuming any more layout space as if it were never there.
lst.Hide
Hide the control but keep the layout space free.
lst.InsertItem
Inserts an item at s specific index in the list.
lst.IsEnabled
Returns whether the control is currently useable by the user.
lst.IsOverlap
Returns whether the control overlaps with another by a given distance.
lst.IsVisible
Returns whether the control is currently visible to the user, ignoring overlaying controls.
lst.Method
Allows access to other functions defined on the object in Java via reflection.

Note: This function is a premium feature. Please consider subscribing to Premium to use this feature and support DroidScript in its further development.
lst.RemoveAll
Removes all entries of the list.
lst.RemoveItem
Removes an item with a specific title from the list.
lst.RemoveItemByIndex
Removes an item on a specific index from the list
lst.ScrollToItem
Scrolls the list to an item with a specific title.
lst.ScrollToItemByIndex
Scrolls the list to an item on a specific index.
lst.SelectItem
Highlights an item with a specific title.
lst.SelectItemByIndex
Highlights an item on a specific index.
lst.SetBackAlpha
Set the transparency of the background by an alpha value between 0 (no transparency) and 0.99 (full transparent) or 1 (no transparency) and 256 (full transparent)
lst.SetBackColor
Changes the background color of the control.
lst.SetBackGradient
Define the background color of the control with a gradient. The default gradient direction is from top to bottom, but you can change it from left to right and the reversed versions of course.
lst.SetBackGradientRadial
Define a radial color gradient for the background of control.
lst.SetBackground
Changes the background to an image which can be repeated using the repeat option.
An image which is often used with that option is '/res/drawable/pattern_carbon' - try it out!
lst.SetColorFilter
Adjust the visual color effect with a color and a given BlendMode. More information about BlendMode can be found in the Android Developer page.
lst.SetColumnWidths
Changes the coloumn withs for title, body and icon. Often used with the “Horiz” option.
lst.SetDivider
Changes the item divider height and color.
lst.SetEllipsize
Will cause the inner text to be broken with ... at the start or the end if it cannot fit in the control.
lst.SetEllipsize1
Will cause the element titles to be broken with ... at the start or the end if it cannot fit in the control.
lst.SetEllipsize2
Will cause the element bodies to be broken with ... at the start or the end if it cannot fit in the control.
lst.SetEnabled
En/Disable the control physically and visually so that the user can/can not access the control. Events like OnTouch will still be fired.
lst.SetFontFile
Change the font style by defining a font file.
lst.SetHiTextColor1
Change the highlight color of titles when selected.
lst.SetHiTextColor2
Change the highlight color of bodies when selected.
lst.SetIconMargins
Change the outer icon border distance.
lst.SetIconSize
Changes the icon size.
lst.SetItem
Change the content of an element with a specific title.
lst.SetItemByIndex
Change the content of an element on a specific index.
lst.SetItemColor
Set the color of a list item.
lst.SetItemColorByIndex
Set the color of a list item by its index.
lst.SetList
Set the content of the whole list.
lst.SetMargins
Define a distance to other controls on each side of the control.
lst.SetOnLongTouch
Define a callback function that is called when the user touches a list item.
lst.SetOnTouch
Define a callback function that is called when the user touches a list item.
lst.SetPadding
Define distances that elements within the control are to maintain from the control borders.
lst.SetPosition
Defines the position and size for the control if the parent is an absolute layout.
lst.SetScale
Scales the control along with its contents by the factors passed to the function.
lst.SetSize
Change the size of the control in either screen relative values or in pixels if the px option was given.
lst.SetTextColor
Change the text color of the contained text.
lst.SetTextColor1
Change the default text color of titles.
lst.SetTextColor2
Change the default text color of bodies.
lst.SetTextMargins
Define a distance to other controls on each side of the control.
lst.SetTextShadow
Define a shadow displayed around the control.
The sun is always shining so there has to be one. Always.
lst.SetTextShadow1
Apply text shadows to titles.
lst.SetTextShadow2
Apply text shadows to bodies.
lst.SetTextSize
Change the size of the contained text.
lst.SetTextSize1
Change the text size for titles.
lst.SetTextSize2
Change the text size for bodies.
lst.SetVisibility
Change the visibility of the control to one of the available modes:
Show: visible
Hide: invisible but still consuming space
Gone: invisible and not consuming space
lst.Show
Set the visibility of the control to “Show”.
lst.Tween
Performs an animation on the control.
The target object is for the position, size and rotation that the control has at the end of the animation.

The type specifies the behavior and the speed of the animation. Separated by a dot, you must also specify whether you want to apply this behavior to the beginning (In), end (Out), or to both (InOut) times of the animation.

With the amount of repeats you can control how many times you want to play the animation.

If you have jojo activated, the animation will alternate between forward and backward playback, so that if the repetition value is odd, the control will be at the start position again at the end of the animation.

Finally the callback function will be called after the animation has finished. Well, it's about time!