简体   繁体   中英

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:

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. Actully I am trying for swipe event on table but that also not working so that I tried touchstart and touchend events. 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. 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. In former releases there was no option to prevent event bubelling.

Swipe is a gesture that is also not provided by 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.

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