Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-16350] ListView: Create a longpress event for listview that return the source of the event

GitHub Issuen/a
TypeNew Feature
PriorityLow
StatusClosed
ResolutionWon't Fix
Resolution Date2014-02-07T01:24:13.000+0000
Affected Version/sRelease 3.1.3, Release 3.2.0
Fix Version/sn/a
Componentsn/a
LabelssupportTeam
ReporterMarco Cota
AssigneeIngo Muschenetz
Created2014-01-31T01:03:24.000+0000
Updated2017-03-22T23:00:00.000+0000

Description

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}

Comments

  1. Radamantis Torres-Lechuga 2014-02-07

    as [~srahim] mentioned, we can not add any event to the listView, all events are supported on childtemplate
  2. Lee Morris 2017-03-22

    Closing ticket as "Won't Fix".

JSON Source