简体   繁体   English

touchstart和touchend事件在Titanium的Tableview上不起作用(Android)

[英]touchstart and touchend events not working on tableview of titanium(Android)

I am developing Android application using Titanium.I want to apply touchstart and touchend event on tableview of titanium.I tried following code: 我正在使用Titanium开发Android应用程序。我想在Titanium的tableview上应用touchstarttouchend事件。我尝试了以下代码:

var userWin = Ti.UI.currentWindow;
var data = [];
for (var i=0;i<5;i++)
{
    var row = Ti.UI.createTableViewRow({height:'auto',className:"row"});
    var username = Ti.UI.createLabel(
    {
        text:'user name',
        height:'auto',
        font:{fontSize:12, fontFamily:'Helvetica Neue', color:'#000'},
        width:'auto',
        color:'#000',
        textAlign:'left',
        top:0,
        left:35,
    });row.add(username);
    var imageView = Ti.UI.createImageView(
    {
        image:'../images/user.png',
        left:0,
        top:0,
        height:25,
        width:25
    });row.add(imageView);          
}
usertable_table.setData(data);
userWin.add(feed_table);    

userWin.addEventListener('touchstart', function(e){
    alert(e.x);
  // Ti.API.debug(['row touchstart', e]); 
});

if I click on row of table it's not giving pop-up, not applying touchstart event.But if I click on element of row like image or name, it's giving output ie vale of ex .Even if I apply both event on current window it,s giving output.But if I apply on row of table view or table view it's not working. 如果我单击表的行,则不会弹出,不应用touchstart事件。但是,如果我单击行的元素(如图像或名称),则会给出输出,即ex of vale。即使我将两个事件都应用于当前窗口, ,s提供输出。但是,如果我在表格视图或表格视图的行上应用它不起作用。 Actully I am trying for swipe event on table but that also not working so that I tried touchstart and touchend events. 实际上,我正在尝试在桌子上滑动事件,但也无法正常工作,因此我尝试了touchstart和touchend事件。 Is there any way to solve this problem. 有什么办法可以解决这个问题。

Sorry but as you can read in Titanium Docs Android still doesn't provide touchstart and touchend for TableViewRow. 抱歉,但您可以在Titanium Docs中阅读, Android仍然不为TableViewRow提供touchstarttouchend Maybe you found an other solution but maybe someone else is having similar trouble and so i want to provide an idea for a possible solution. 也许您找到了其他解决方案,但也许其他人也遇到了类似的麻烦,因此我想提供一个可行解决方案的想法。 Unfortunately you can add a listener to the row and then you can click on a element of this row. 不幸的是,您可以在该行中添加一个侦听器,然后可以单击该行的元素。 This works because of event bubbeling which you can control in SDK 3.0.0 and newer. 之所以能够成功,是因为您可以在SDK 3.0.0及更高版本中控制事件的冒泡。 In former releases there was no option to prevent event bubelling. 在以前的版本中,没有防止事件冒泡的选项。

Swipe is a gesture that is also not provided by Android. 滑动是Android也不提供的手势。 If you want to use a swipe-similar gesture you could place a transparent view on top of all elements within a row. 如果要使用类似滑动的手势,可以在行中所有元素的顶部放置一个透明视图。

Ti.UI.createView({
  width: Ti.UI.FILL,
  height: Ti.UI.FILL, //should be row height, can be set explicitely if known
  backgroundColor: '#0000', //should be transparent
});

Then you can apply all algorithms for swipe-similar gesture to this view. 然后,您可以将所有用于类似滑动手势的算法应用到该视图。 Though this vie is the top-most element available to the user it should react on all user input. 尽管这是用户可用的最顶层的元素,但它应该对所有用户输入做出反应。 But be aware that listeners on other elements behind this transparent view will not react anymore. 但是请注意,此透明视图后面其他元素上的侦听器将不再作出反应。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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