Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

1.3 Android: OnClick Event not fired on ImageView inside ScrollView

Title says it all. The nesting is as follows:

Win->ScrollView->View->ImageView

OnClick fires fine if the ImageView is only within another view. As soon as the View is inside a ScrollView, the OnClick event is not fired.

I believe this was introduced in 1.3 since it was working fine under 1.2.

Looking at the source, there were definitely made some changes to the onclick handling, but I can't figure out what exactly is wrong.

Any hints on this are appreciated :)

— asked May 14th 2010 by Nils
  • 1.3
  • android
  • imageview
  • mobile
  • onclick
  • scrollview
0 Comments

3 Answers

  • Hi,
    I'm having the same problem, it works on the iPhone but not on the Andoid.
    I tried also to put the listener on the image view, but nothing gets triggered.
    Is there a way to solve this?
    Thanks

    — answered June 13th 2010 by Daniele Sangalli
    permalink
    0 Comments
  • Hey Barry..

    It's possible that the ScrollView's drag logic is overriding our touch listener on the ImageView.. does it work if the ImageView is the only child of the ScrollView? (i.e. Win->ScrollView->ImageView)

    — answered May 14th 2010 by Marshall Culpepper
    permalink
    0 Comments
  • Thanks for the reply!
    I'm not quite sure how to add the imageview to the scrollview. But the click event fires if it's done like so:

    var scrollView = Titanium.UI.createScrollableView({});
    scrollView.add(imageview);
    

    However, this make the scrollview kind of useless..

    Here is a full code example. The event is fired on iPhone but not on Android

    var win = Titanium.UI.currentWindow;
    var image = Ti.Filesystem.getFile(Titanium.Filesystem.resourcesDirectory,'images/image.png');
    var imageview = Ti.UI.createImageView({image:image});
    imageview.addEventListener('click', function(e) {
        alert('X');
    });
    var views = [];
    views[0] = Ti.UI.createView({
        backgroundColor:'#336699'
    });
    
    views[0].add(imageview);
    var scrollView = Titanium.UI.createScrollableView({
        views: views
    });
    win.add(scrollView);
    
    — answered May 15th 2010 by Nils
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.