Can widget.newScrollView have params like widget.newTableView()?

Hi,

I used widget.newTableView() and I really found the params option to be very useful in the insertRow(options)method.

Now I want to create a similar table view but with more than one column. I wasn’t sure if I could have more than one column using a table view so I used widget.newScrollView() and displayed a list of objects in 2 separate columns (see screenshot). However, I do not know how to create a method that allows the user to tap/touch an item. I don’t know how to create/send the item id or name or any param.

Can someone advise me on the best way to approach this?

Thanks in advance.

The params are useful for tableViews because tableViews have to render each row. ScrollViews don’t have such a rendering feature, they are really just a display.newGroup() with scrolling controls added. You just insert a display object in a scrollView and the scrollView will scroll the group around.

As for the best way to know what’s being tapped on, you can always add an ID to the display object:

local function touchHandlerFunction( event )      print(event.target.name) -- print's "redcar1"      -- do stuff based on the .name parameter      return true end local someObject = display.newImageRect("redcar1.png", 150, 50) someObject.name = "redcar1" scrollView:insert(someObject) someObject:addEventListener("touch", touchHandlerFunction)

or something like that.

Rob

Hi Rob, thanks for the response.

This does what I need however the scrollview no longer scrolls. It scrolls when I comment out the return true but then the touch listener does not trigger without the return true.

So between scrolling and selecting a car, I can only get one to work but not both. I removed the listener option when I create the newScrollView.

You might want to look into this API call: http://docs.coronalabs.com/api/type/ScrollViewWidget/takeFocus.html

If you detect in your touch listener that you’re trying to move the scrollView instead of interact with the item, you need to call this takeFocus() API to pass the touch to the scrollView.

Rob

Rob, YOU ARE AWESOME!

Thanks so much for the helpful, super quick replies :slight_smile:

You made my week! You’re the man!

The params are useful for tableViews because tableViews have to render each row. ScrollViews don’t have such a rendering feature, they are really just a display.newGroup() with scrolling controls added. You just insert a display object in a scrollView and the scrollView will scroll the group around.

As for the best way to know what’s being tapped on, you can always add an ID to the display object:

local function touchHandlerFunction( event )      print(event.target.name) -- print's "redcar1"      -- do stuff based on the .name parameter      return true end local someObject = display.newImageRect("redcar1.png", 150, 50) someObject.name = "redcar1" scrollView:insert(someObject) someObject:addEventListener("touch", touchHandlerFunction)

or something like that.

Rob

Hi Rob, thanks for the response.

This does what I need however the scrollview no longer scrolls. It scrolls when I comment out the return true but then the touch listener does not trigger without the return true.

So between scrolling and selecting a car, I can only get one to work but not both. I removed the listener option when I create the newScrollView.

You might want to look into this API call: http://docs.coronalabs.com/api/type/ScrollViewWidget/takeFocus.html

If you detect in your touch listener that you’re trying to move the scrollView instead of interact with the item, you need to call this takeFocus() API to pass the touch to the scrollView.

Rob

Rob, YOU ARE AWESOME!

Thanks so much for the helpful, super quick replies :slight_smile:

You made my week! You’re the man!