Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Can widget.newScrollView have params like widget.newTableView()?
Started by elifares Oct 30 2018 05:21 PM

4 replies to this topic
newscrollview newtableview params widget insertrow

Best Answer Rob Miracle , 31 October 2018 - 08:08 AM

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

[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

elifares

[GLOBAL: userInfoPane.html]
elifares
  • Enthusiast

  • 86 posts
  • Corona SDK

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.

Attached Files



[TOPIC: post.html]
#2

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,072 posts
  • Enterprise

  Best Answer

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



[TOPIC: post.html]
#3

elifares

[GLOBAL: userInfoPane.html]
elifares
  • Enthusiast

  • 86 posts
  • Corona SDK

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.



[TOPIC: post.html]
#4

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 26,072 posts
  • Enterprise

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



[TOPIC: post.html]
#5

elifares

[GLOBAL: userInfoPane.html]
elifares
  • Enthusiast

  • 86 posts
  • Corona SDK

Rob, YOU ARE AWESOME!

 

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

 

You made my week! You're the man!




[topic_controls]
[/topic_controls]