Egret之List使用示例

class Main extends egret.DisplayObjectContainer{
    public constructor()
    {
        super();
        this.addEventListener(egret.Event.ADDED_TO_STAGE,this.onAddToStage,this);
    }
    private list: eui.List;
    public onAddToStage(event: egret.Event): void
    {
        var exml = `
          `;
        var list = new eui.List();
        list.dataProvider = new eui.ArrayCollection(["item1","item2","item3"]);
        list.itemRendererSkinName = exml;
        this.addChild(list);
        this.list = list;
        list.selectedIndex = 1;//设置默认选中项

        list.allowMultipleSelection = true;//开启多选
        list.requireSelection = true;//至少选择一个
        list.addEventListener(eui.ItemTapEvent.ITEM_TAP,this.onChange,this);

    }
    private onChange(e: eui.PropertyEvent): void
    {
        //获取点击消息
        console.log(this.list.selectedItem,this.list.selectedIndex)
    }
}

 



Bookmark the permalink.

Comments are closed.