Class ccui.ListView

Class Summary
Constructor Attributes Constructor Name and Description
 
The list view control of Cocos UI.

Method Summary

Class Detail

ccui.ListView()
The list view control of Cocos UI.
var listView = new ccui.ListView();
// set list view ex direction
listView.setDirection(ccui.ScrollView.DIR_VERTICAL);
listView.setTouchEnabled(true);
listView.setBounceEnabled(true);
listView.setBackGroundImage("res/cocosui/green_edit.png");
listView.setBackGroundImageScale9Enabled(true);
listView.setContentSize(cc.size(240, 130));
this.addChild(listView);

Field Detail

<static> <constant> ccui.ListView.EVENT_SELECTED_ITEM
The flag selected item of ccui.ListView's event.
<static> <constant> ccui.ListView.GRAVITY_BOTTOM
The bottom flag of ccui.ListView's gravity.
<static> <constant> ccui.ListView.GRAVITY_CENTER_HORIZONTAL
The center horizontal flag of ccui.ListView's gravity.
<static> <constant> ccui.ListView.GRAVITY_CENTER_VERTICAL
The center vertical flag of ccui.ListView's gravity.
<static> <constant> ccui.ListView.GRAVITY_LEFT
The left flag of ccui.ListView's gravity.
<static> <constant> ccui.ListView.GRAVITY_RIGHT
The right flag of ccui.ListView's gravity.
<static> <constant> ccui.ListView.GRAVITY_TOP
The top flag of ccui.ListView's gravity.
<static> <constant> ccui.ListView.MAGNETIC_BOTH_END
The flag of ccui.ListView's magnetic both end type.
ListView tries to align its items in left or right end if it is horizontal, top or bottom in vertical.
The aligning side (left or right, top or bottom) is determined by user's scroll direction.
<static> <constant> ccui.ListView.MAGNETIC_BOTTOM
The flag of ccui.ListView's magnetic bottom type.
<static> <constant> ccui.ListView.MAGNETIC_CENTER
The flag of ccui.ListView's magnetic center type.
ListView tries to align its items in center of current view.
<static> <constant> ccui.ListView.MAGNETIC_LEFT
The flag of ccui.ListView's magnetic left type.
<static> <constant> ccui.ListView.MAGNETIC_NONE
The flag of ccui.ListView's magnetic none type.
<static> <constant> ccui.ListView.MAGNETIC_RIGHT
The flag of ccui.ListView's magnetic right type.
<static> <constant> ccui.ListView.MAGNETIC_TOP
The flag of ccui.ListView's magnetic top type.
<static> <constant> ccui.ListView.ON_SELECTED_ITEM_END
The flag selected item end of ccui.ListView's event.
<static> <constant> ccui.ListView.ON_SELECTED_ITEM_START
The flag selected item start of ccui.ListView's event.

Method Detail

  • addChild(widget, zOrder, tag)
    add child to ListView
    Parameters:
    {cc.Node} widget
    {Number} zOrder Optional
    {Number|String} tag Optional
    tag or name
  • addEventListener(selector)
    Adds callback function called ListView event triggered
    Parameters:
    {Function} selector
  • addEventListenerListView(selector, target)
    Adds event listener to ccui.ListView.
    Parameters:
    {Function} selector
    {Object} target Optional
    Deprecated:
    since v3.0, please use addEventListener instead.
  • <static> ccui.ListView.create()
    allocates and initializes a UIListView.
    Deprecated:
    since v3.0, please use new ccui.ListView() instead.
  • ctor()
    allocates and initializes a UIListView. Constructor of ccui.ListView, override it to extend the construction behavior, remember to call "this._super()" in the extended "ctor" function.
    // example
    var aListView = new ccui.ListView();
  • doLayout()
    provides a public _doLayout function for Editor. it calls _doLayout.
  • {?ccui.Widget} getBottommostItemInCurrentView()
    Query the topmost item in horizontal list
    Returns:
    {?ccui.Widget} A item instance.
  • {?ccui.Widget} getCenterItemInCurrentView()
    Query the center item
    Returns:
    {?ccui.Widget} A item instance.
  • {?ccui.Widget} getClosestItemToPosition(targetPosition, itemAnchorPoint)
    Query the closest item to a specific position in inner container.
    Parameters:
    {cc.Point} targetPosition
    Specifies the target position in inner container's coordinates.
    {cc.Point} itemAnchorPoint
    Specifies an anchor point of each item for position to calculate distance.
    Returns:
    {?ccui.Widget} A item instance if list view is not empty. Otherwise, returns null.
  • {?ccui.Widget} getClosestItemToPositionInCurrentView(positionRatioInView, itemAnchorPoint)
    Query the closest item to a specific position in current view.
    For instance, to find the item in the center of view, call 'getClosestItemToPositionInCurrentView(cc.p(0.5, 0.5), cc.p(0.5, 0.5))'.
    Parameters:
    {cc.Point} positionRatioInView
    Specifies the target position with ratio in list view's content size.
    {cc.Point} itemAnchorPoint
    Specifies an anchor point of each item for position to calculate distance.
    Returns:
    {?ccui.Widget} A item instance if list view is not empty. Otherwise, returns null.
  • {number} getCurSelectedIndex()
    Returns current selected index
    Returns:
    {number}
  • {string} getDescription()
    Returns the "class name" of ccui.ListView.
    Returns:
    {string}
  • {Number} getIndex(item)
    Returns the index of item.
    Parameters:
    {ccui.Widget} item
    the item which need to be checked.
    Returns:
    {Number} the index of item.
  • {ccui.Widget} getItem(index)
    Returns a item whose index is same as the parameter.
    Parameters:
    {Number} index
    Returns:
    {ccui.Widget}
  • {Array} getItems()
    Returns the item container.
    Returns:
    {Array}
  • {Number} getItemsMargin()
    Returns the margin between each item.
    Returns:
    {Number}
  • {?ccui.Widget} getLeftmostItemInCurrentView()
    Query the leftmost item in horizontal list
    Returns:
    {?ccui.Widget} A item instance.
  • {boolean} getMagneticAllowedOutOfBoundary()
    Query whether the magnetic out of boundary is allowed.
    Returns:
    {boolean}
  • {number} getMagneticType()
    Get magnetic type of ListView.
    Returns:
    {number}
  • {?ccui.Widget} getRightmostItemInCurrentView()
    Query the rightmost item in horizontal list
    Returns:
    {?ccui.Widget} A item instance.
  • {?ccui.Widget} getTopmostItemInCurrentView()
    Query the topmost item in horizontal list
    Returns:
    {?ccui.Widget} A item instance.
  • insertCustomItem(item, index)
    Push back custom item into ccui.ListView.
    Parameters:
    {ccui.Widget} item
    {Number} index
  • insertDefaultItem(index)
    Insert a default item(create by a cloned model) into ListView.
    Parameters:
    {Number} index
  • interceptTouchEvent(eventType, sender, touch)
    Intercept touch event, handle its child's touch event.
    Parameters:
    {Number} eventType
    {ccui.Widget} sender
    {cc.Touch} touch
  • jumpToItem(itemIndex, positionRatioInView, itemAnchorPoint)
    Jump to specific item
    Parameters:
    {number} itemIndex
    Specifies the item's index
    {cc.Point} positionRatioInView
    Specifies the position with ratio in list view's content size.
    {cc.Point} itemAnchorPoint
    Specifies an anchor point of each item for position to calculate distance.
  • pushBackCustomItem(item)
    Push back custom item into ListView.
    Parameters:
    {ccui.Widget} item
  • pushBackDefaultItem()
    Push back a default item(create by a cloned model) into ListView.
  • refreshView()
    Refreshes list view.
    Deprecated:
    Use method forceDoLayout() instead
  • removeAllChildren()
    Removes all children from ccui.ListView.
  • removeAllChildrenWithCleanup(cleanup)
    Removes all children from ccui.ListView and do a cleanup all running actions depending on the cleanup parameter.
    Parameters:
    {Boolean} cleanup
  • removeAllItems()
    Removes all items from ccui.ListView.
  • removeChild(widget, cleanup)
    remove child from ListView
    Parameters:
    {cc.Node} widget
    {Boolean} cleanup Optional, Default: true
  • removeItem(index)
    Removes a item whose index is same as the parameter.
    Parameters:
    {Number} index
  • removeLastItem()
    Removes the last item of ccui.ListView.
  • requestRefreshView()
    Requests refresh list view.
    Deprecated:
    Use method requestDoLayout() instead
  • scrollToItem(itemIndex, positionRatioInView, itemAnchorPoint, timeInSec)
    Scroll to specific item
    Parameters:
    {number} itemIndex
    Specifies the item's index
    {cc.Point} positionRatioInView
    Specifies the position with ratio in list view's content size.
    {cc.Point} itemAnchorPoint
    Specifies an anchor point of each item for position to calculate distance.
    {number} timeInSec Optional, Default: 1.0
    Scroll time
  • setDirection(dir)
    Changes scroll direction of ccui.ListView.
    Parameters:
    {ccui.ScrollView.DIR_NONE | ccui.ScrollView.DIR_VERTICAL | ccui.ScrollView.DIR_HORIZONTAL | ccui.ScrollView.DIR_BOTH} dir
  • setGravity(gravity)
    Changes the gravity of ListView.
    Parameters:
    {ccui.ListView.GRAVITY_LEFT|ccui.ListView.GRAVITY_RIGHT|ccui.ListView.GRAVITY_CENTER_HORIZONTAL|ccui.ListView.GRAVITY_BOTTOM|ccui.ListView.GRAVITY_CENTER_VERTICAL} gravity
  • setItemModel(model)
    Sets a item model for ListView. A model will be cloned for adding default item.
    Parameters:
    {ccui.Widget} model
  • setItemsMargin(margin)
    Changes the margin between each item.
    Parameters:
    {Number} margin
  • setMagneticAllowedOutOfBoundary(magneticAllowedOutOfBoundary)
    Set magnetic allowed out of boundary.
    Parameters:
    {boolean} magneticAllowedOutOfBoundary
  • setMagneticType(magneticType)
    Set magnetic type of ListView.
    Parameters:
    {ccui.ListView.MAGNETIC_NONE|ccui.ListView.MAGNETIC_CENTER|ccui.ListView.MAGNETIC_BOTH_END|ccui.ListView.MAGNETIC_LEFT|ccui.ListView.MAGNETIC_RIGHT|ccui.ListView.MAGNETIC_TOP|ccui.ListView.MAGNETIC_BOTTOM} magneticType