简体   繁体   中英

How to set events on Listview in Titanium using XML Alloy Markup

From here I know events cannot be set on the ListView or on the ListItem(Data) directly. But can be set as below code.

var listView = Ti.UI.createListView({
  // …
  templates: {
    "simple": {
      // …
      events: {
        "longpress": function (event) {
          Ti.API.warn(event.itemId); // Works! ;)
        }
      }
    }
  }
});

But my question is how can I set the same using XML Mark up. My listview is like this

<ListView   id="messageList" onItemclick="openPagerMessageDetails"  >
    <Templates   >
        <ItemTemplate     id="lstTemplate" name="messageListtemplate" >
            <View  id="myCustomView" ></View>
        </ItemTemplate>

    </Templates>
    <ListSection   id="lstSection" ></ListSection>
</ListView>

This is quite old, but according to Appcelerator Wiki , when you have your template in view, you can add an event listener to particular view as usual by adding onClick="" (I assume it works with other events as well).

<Templates>
    <ItemTemplate id="lstTemplate" name="messageListtemplate">
        <View id="myCustomView" onClick="doClick" ></View>
    </ItemTemplate>
</Templates>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM