develop wherever and whenever you want...
Docs > ListView Class Reference

ListView Class Reference

Summary 
ListView is a simplified implementation of iOS UITableView. It provides a list of text items and mechanisms to manage list content. ListView also provides notification of selection changes. void addItems(items) 
void setItem(index,item) 
void clear() 
void onClick(handler) 
void removeItem(index) 
number getSelected() 
string getItem(index) 
number getCount() 
void setSelected(index) 
Example 
r = new View("ipad-portrait"); 
l = r.createListView(r.width,r.height); 
items = ["apple", "orange"]; 
l.addItems(items); 
l.setItem(2,"banana"); 
l.setSelected(2); 
l.setItem(3,"remove me"); 
document.writeln(l.getCount()); 
l.removeItem(3); 
function sel(sender) { 
var s = sender.getSelected(); 
s += ":" + sender.getItem(s); 
document.writeln(s); 
}

l.onClick(sel); 
document.wait(); 


addItems 
Add an array of items to the list

void addItems(items)

Parameters 
items - array of string items to add to list

Return Value 
none

Notes 
Items are inserted at the end of the list


setItem 
Update or insert item

void setItem(index,item)

Parameters 
index - item position in the list 
item - item text

Return Value 
none

Notes 
If an item exists at the given index, the item is replaced, otherwise, the item is inserted at the end of the list (regardless of index).


clear 
Clear all items from the list

void clear()

Parameters 
none

Return Value 
none

Notes


onClick 
Register event handler to receive selection change events

void onClick(handler)

Parameters 
handler - function to receive selection change events

Return Value 
none

Notes 
Handler function is in the form

function <handler>(sender)

Where sender is the ListView object


removeItem 
Remove an item from the list

void removeItem(index)

Parameters 
index index of item to remove

Return Value 
none

Notes

getSelected 
Get the index of the selcted list item

number getSelected()

Parameters 
none

Return Value 
Index of list item starting with 0 for the first item. -1 is returned if there are no selected items

Notes


getItem 
Return the text of an item given its index

string getItem(index)

Parameters 
index - position of item in the list

Return Value 
Text of item at given index or null if index is out of bounds

Notes


getCount 
Get the number of items in the list view

number getCount()

Parameters 
none

Return Value 
Returns the count of items in the list view

Notes


setSelected 
Sets the selection to an item in the list

void setSelected(index)

Parameters 
index - position of item to select. -1 to unselect items

Return Value 
none

Notes