Request
Customer is asking us to provide longpress event at the same hierarchy level as the itemclick event, they have a listView item with multiple labels and they want to be able to longpress any of this labels and call a function depending on the label pressed.
Workaround
We currently have recommended to assign a longpress event listener to each label in the item template in order to be able to retrieve the source of the event, customer have commented they have a large number of components in my template that need to detect and they will prefer to have a single event listener.
<ItemTemplate name="odd" height="60" accessoryType="Ti.UI.LIST_ACCESSORY_TYPE_CHECKMARK">
<View id="handler" >
<Label bindId="heading" id="heading" onLongpress="longCB"/>
<Label bindId="subheading" id="subheading" onLongpress="longCB"/>
</View>
</ItemTemplate>
Current Behavior
If we assign a longpress event from a view inside a item template in a listView this will return the information of the row (section and index) but no the one of the label being pressed.
<Alloy>
<Window title="ListView">
<ListView id="list" defaultItemTemplate="odd">
<Templates>
<ItemTemplate name="odd" height="60" accessoryType="Ti.UI.LIST_ACCESSORY_TYPE_CHECKMARK">
<View id="handler" onLongpress="longCB">
<Label bindId="heading" id="heading" />
<Label bindId="subheading" id="subheading" />
</View>
</ItemTemplate>
</Templates>
<ListSection id="section">
</ListSection>
</ListView>
</Window>
</Alloy>
JS controller
function longCB(e){
Ti.API.info(JSON.stringify(e));
};
Console log on longpress
[INFO] : {"y":17,"sectionIndex":0,"section":{"id":"section"},"itemIndex":4,"x":88,"bubbles":true,"type":"longpress","source":{"horizontalWrap":true},"cancelBubble":false}
When calling the longpress event from a view outside the template this will return the information regarding the label calling the event.
<Window title="ListView">
<View id="handler" onLongpress="longCB">
<Label bindId="heading" id="heading" >Test 1</Label>
<Label bindId="subheading" id="subheading" >test 2</Label>
</View>
</Window>
JS controller
function longCB(e){
Ti.API.info(JSON.stringify(e));
};
Console log on longpress
[INFO] : {"x":27,"y":12,"bubbles":true,"type":"longpress","source":{"text":"test 2","left":60,"id":"subheading","horizontalWrap":true,"color":"black","top":25,"bindId":"subheading"},"cancelBubble":false}
as [~srahim] mentioned, we can not add any event to the listView, all events are supported on childtemplate
Closing ticket as "Won't Fix".