Android 用于ListSection数组的钛事件侦听器

Android 用于ListSection数组的钛事件侦听器,android,events,titanium,appcelerator,addeventlistener,Android,Events,Titanium,Appcelerator,Addeventlistener,我在appcelerator,Titanium中有一个问题:如何动态地概括EventListener?在我的项目中,我有一个动态创建的listSection数组。问题是,如何创建一个事件侦听器,使整个listView共享相同的事件行为 var sections = []; var SectionOne = Ti.UI.createListSection({ headerTitle : "Section one" }); var SectionTwo = Ti.UI.cr

我在appcelerator,Titanium中有一个问题:如何动态地概括
EventListener
?在我的项目中,我有一个动态创建的
listSection
数组。问题是,如何创建一个事件侦听器,使整个
listView
共享相同的事件行为

var sections = [];

var SectionOne = Ti.UI.createListSection({
        headerTitle : "Section one"
    });
var SectionTwo = Ti.UI.createListSection({
        headerTitle : "Section two"
    });
var SectionThree = Ti.UI.createListSection({
        headerTitle : "Section three"
    });

sections.push(SectionOne);
sections.push(SectionTwo);
sections.push(SectionThree);

/*problem below*/
listView.addEventListener('itemclick', function(e) {
    for (var sec in sections) {
        var item = sections[sec].getItemAt(e.itemIndex);
        if (item.properties.accessoryType == Ti.UI.LIST_ACCESSORY_TYPE_NONE) {
            audioPlayer.start();
            item.properties.accessoryType = Ti.UI.LIST_ACCESSORY_TYPE_CHECKMARK;
            item.properties.color = 'red';
            Ti.API.info('e.index: ' + e.itemIndex);
        } else {
            audioPlayer.stop();
            item.properties.accessoryType = Ti.UI.LIST_ACCESSORY_TYPE_NONE;
            item.properties.color = 'black';
        }
        sections[sec].updateItemAt(e.itemIndex, item);
    }
});
win.add(listView);

如果您想获取节索引,我希望它对您有所帮助:

listView.addEventListener('itemclick', function(e) {

    alert("SectionID" + data.sessions[e.sectionIndex].Session_Name);
});

还是不明白这个问题或者这里有什么问题