kuni
kuni

Reputation: 33

onTouchstart event not fire in Listview(Alloy) only Android

view xml(List view template)

<Alloy>
  <ItemTemplate id="test">

    <View onTouchstart="touch" width="Ti.UI.SIZE" height="Ti.UI.SIZE">
      <Label>test</Label>
    </View>

  </ItemTemplate>
</Alloy>

controller js

function touch(e){
  Ti.API.debug('touch!!');
};

not fire only android..(iOS is good)

and under don't use ListView code, no problem android(and iOS).

<Alloy>
  <Window class="container">
    <View onTouchstart="touch" width="Ti.UI.SIZE" height="Ti.UI.SIZE">
      <Label>test</Label>
    </View>
  </Window>
</Alloy>

I do not know anyone solution?

Upvotes: 1

Views: 207

Answers (1)

rjcpereira
rjcpereira

Reputation: 953

There are no 'touchstart' method for ListViews, you could use 'dragstart' and 'scrollstart' as alternative.

Check out the available events:

http://docs.appcelerator.com/platform/latest/#!/api/Titanium.UI.ListView

I've tried once to add the 'change' event to a TextField inside the ItemTemplace, but I've to create an workaround:

Change event on TextField inside ListView Template

If it's not possible, you have to use the 'itemclick' and get the selected row:

$.list.addEventListener('itemclick',function(list) {

    var row = $.list.sections[0].getItemAt(list.itemIndex);

    if(row && row.title) {

        row.title.text = 'hello world';

        //when you click the View with 'cancel' bindId
        if(list.bindId == 'cancel') yourCancelAction();

        //when you click the View with 'save' bindId
        //(if you need to pass the row index to the function, 
        //in order to update something on the clicked row with a external function)
        if(list.bindId == 'save') yourSaveAction(list.itemIndex);

        $.list.sections[0].updateItemAt(list.itemIndex,row);
    }

    list = row = null;
});

Upvotes: 1

Related Questions