【问题标题】:onTouchstart event not fire in Listview(Alloy) only AndroidonTouchstart 事件仅在 Android 的 Listview(Alloy) 中不触发
【发布时间】:2016-08-31 09:40:05
【问题描述】:

查看xml(列表视图模板)

<Alloy>
  <ItemTemplate id="test">

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

  </ItemTemplate>
</Alloy>

控制器js

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

不只触发android..(iOS 很好)

并且在不使用ListView的代码下,android(和iOS)没问题。

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

不知道有没有人解决?

【问题讨论】:

    标签: android titanium appcelerator titanium-alloy


    【解决方案1】:

    ListViews 没有 'touchstart' 方法,您可以使用 'dragstart' 和 'scrollstart' 作为替代。

    查看可用事件:

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

    我曾尝试将“更改”事件添加到 ItemTemplace 内的 TextField,但我必须创建一个解决方法:

    Change event on TextField inside ListView Template

    如果不可能,您必须使用“itemclick”并获取选定的行:

    $.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;
    });
    

    【讨论】:

    • 感谢回复,但是,ItemTemplate 在列表视图之上。我想检测查看触摸事件内部列表视图。
    • 感谢里卡多!如果我可能不清楚,我很抱歉。例如不同的情况,ItemTemplate 有两个视图(如按钮)。我想单独检测动作事件..
    • 我已经用你需要的东西更新了我的答案,你得到了你点击的对象的 bindId,然后做你的事情
    猜你喜欢
    • 1970-01-01
    • 2021-10-19
    • 1970-01-01
    • 2016-07-30
    • 1970-01-01
    • 1970-01-01
    • 2020-11-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多