Menu with return value

Hello,

I am having issue about designing a solution to this simple task.

I have a code like this: (just

require(“menu”)

code line1

code line2

code line3

table = aTable

selection = menu.getselection(aTable)

doaTask(selection)

doanotherTask(selection)

code line8

code line9

end

The problem is line after line5 should be executed only after line five is executed. In line5, I created a tableview (as part of external module), which shows the menu items and on row touch, return the value back to selection. However the code obviously don’t stop for a until a touch event is fired. In this general case, how may I solve the task? Help appreciated.

You will need to listen for the row touch event and perform your logic there.

http://docs.coronalabs.com/daily/api/library/widget/newTableView.html#onrowtouch-optional

Hello @develephant,

Thanks for the reply.

But the issue is that I want to wait till the user touches the row. However ,as we know, the code will create a table and we can writeaction on the onrowtouch listener, But that will only “register the listener”. I want to get the feedback and then only proceed to subsquent lines of code

Without more code it’s hard to put into context what you are asking.  If I understand your question, then it would appear you are trying to trigger some code when someone touched the menu, in which case I’ll assume you have something like this set up?

[lua]

local function onRowTouch( event )

 --do stuff here when the user touched the list item

end

local tableView = widget.newTableView

  {

      top = 0,

      left = 0,

      height = display.contentHeight,

      width = display.contentWidth,

      onRowTouch = onRowTouch,

  }

[/lua]

If your “listener” code is in a module, then are you trying to get the information from the module elsewhere?

You say you want to listen for “feedback” what feedback are you looking for specifically?  A row index?

I’d like to understand your issue better so I can help.  If you do supply some code, please wrap it in the “lua” tag when using the editor.

Cheers.

Hi @develep hant,

Thanks for your reply. I will explain it better

I have a button, with a default label in it. There is a set of values suitable for the button label. This is stored in a lua table, I want user to be able to pick a label and change the default value

So putting it simple, in the on_release event of the button, I want to display a menu which will appear as kind of overlay.

I create a table view with all the values in the table and show it on the top of the screen. When the user touches a particular row, that value will be given to the label.

But as you can see, assigning value to the button label, need to be waited till user picks a row. I want the “menu_of_labels” and the “button” don’t be part of the other. So I create table view in an external module, passing “table of labels” into it, which creates table view. I want the return value of the table view to be “user_pick”, but see that it is not possible because once the table view is created, external module is over and I come back to my main “button on_release listener” which want for the “selected label”, so that it could be assigned to the button. How can the make the external module persist till user picks a value? I think the lua code is hard to put concisely.

Thanks for the clarification. Just to make sure I understand…

You have a button with a dynamic label. When user taps the button, label choices appear in a tableView that you overlay on the screen. When user selects label from tableView it will update label on button and close tableView. Is that correct?

Here is my recommendation, and probably the simplest way.  I can provide a code example if needed.

When you call your module that contains the tableView, you can also pass a reference to the button and use that.  As an example:

[lua]

mymod.openLabelSelection( buttonRef ) --opens label options mod

[/lua]

In the external mod…

[lua]

buttonRef:setLabel( tableViewValue ) --user selects the row index

[/lua]

Does that help at all?

Hello @dev-elephant

Thanks for your time and effort. I also finally reached in that conclusion.

But that violates “my wish”, that each be not part of the other. Like, the overlay act just like a function which returns the selected value, given list of choices. In that case, it would have been a much reusable element.

But I guess, buttons are where this is applied most. So putting “setLabel” function of button, inside “row touch” event listener, would be safe as long as I limit the program to call this module only for buttons.

Thank you,

looking forward to more occasions,

Appu George.

You will need to listen for the row touch event and perform your logic there.

http://docs.coronalabs.com/daily/api/library/widget/newTableView.html#onrowtouch-optional

Hello @develephant,

Thanks for the reply.

But the issue is that I want to wait till the user touches the row. However ,as we know, the code will create a table and we can writeaction on the onrowtouch listener, But that will only “register the listener”. I want to get the feedback and then only proceed to subsquent lines of code

Without more code it’s hard to put into context what you are asking.  If I understand your question, then it would appear you are trying to trigger some code when someone touched the menu, in which case I’ll assume you have something like this set up?

[lua]

local function onRowTouch( event )

 --do stuff here when the user touched the list item

end

local tableView = widget.newTableView

  {

      top = 0,

      left = 0,

      height = display.contentHeight,

      width = display.contentWidth,

      onRowTouch = onRowTouch,

  }

[/lua]

If your “listener” code is in a module, then are you trying to get the information from the module elsewhere?

You say you want to listen for “feedback” what feedback are you looking for specifically?  A row index?

I’d like to understand your issue better so I can help.  If you do supply some code, please wrap it in the “lua” tag when using the editor.

Cheers.

Hi @develep hant,

Thanks for your reply. I will explain it better

I have a button, with a default label in it. There is a set of values suitable for the button label. This is stored in a lua table, I want user to be able to pick a label and change the default value

So putting it simple, in the on_release event of the button, I want to display a menu which will appear as kind of overlay.

I create a table view with all the values in the table and show it on the top of the screen. When the user touches a particular row, that value will be given to the label.

But as you can see, assigning value to the button label, need to be waited till user picks a row. I want the “menu_of_labels” and the “button” don’t be part of the other. So I create table view in an external module, passing “table of labels” into it, which creates table view. I want the return value of the table view to be “user_pick”, but see that it is not possible because once the table view is created, external module is over and I come back to my main “button on_release listener” which want for the “selected label”, so that it could be assigned to the button. How can the make the external module persist till user picks a value? I think the lua code is hard to put concisely.

Thanks for the clarification. Just to make sure I understand…

You have a button with a dynamic label. When user taps the button, label choices appear in a tableView that you overlay on the screen. When user selects label from tableView it will update label on button and close tableView. Is that correct?

Here is my recommendation, and probably the simplest way.  I can provide a code example if needed.

When you call your module that contains the tableView, you can also pass a reference to the button and use that.  As an example:

[lua]

mymod.openLabelSelection( buttonRef ) --opens label options mod

[/lua]

In the external mod…

[lua]

buttonRef:setLabel( tableViewValue ) --user selects the row index

[/lua]

Does that help at all?

Hello @dev-elephant

Thanks for your time and effort. I also finally reached in that conclusion.

But that violates “my wish”, that each be not part of the other. Like, the overlay act just like a function which returns the selected value, given list of choices. In that case, it would have been a much reusable element.

But I guess, buttons are where this is applied most. So putting “setLabel” function of button, inside “row touch” event listener, would be safe as long as I limit the program to call this module only for buttons.

Thank you,

looking forward to more occasions,

Appu George.