how to put text from User input in tableview or something similar..?

Hi,

I have an issue for a long time now, concerning text input from keyboard by an user, which should be stored in different rows of an eg. tableview. 

What I want to do is a simple page with lines (as tableviews look like) where users can click on the first, second, third…etc line and type in a text which is stored the if the line is unmarked, just like it is in iOS “note” or “memo” app. These several lines of user created text shall be stored in a database later on.

I don’t find nowhere any tutorial or something like that, but I guess it’s not good to simple create 10 textboxes one by one just to have 10 lines where to put in text…:confused:

I attached a screenshot with an example how I imagine it to be basically.

would be great if somebody could help me in the case :*

thanks a lot!!!

There is a programming paradigm called “Model-View-Controller” or MVC.   To simplify this, your view is your tableView, your model (i.e. the database) would be a simple Lua table holding the strings and the controller is the logic to draw the tableView (the onRowRender() function of the tableView.

That will handle filling out the table and getting it on screen.

Your input field can either stay at the top, and you can use the tableView’s onRowTouch() to set a flag about which field the input goes to and then put the data entered into the lua table and then insert the data into the row.

This is pretty straight forward, but it’s a bit of work. Your logic for dealing with the table view needs to know if you’re inserting a new row or updating one.  If you touch a row with data in it, then you probably should prepopulate a native.newTextField.

As a design decision, you can keep the field at the top or when someone taps a row, you draw a native.newTextField() over top of the row pre-populate it with the value of that row, and when the row is submitted, hide the keyboard put the text back in the row and get rid of the newTextInput().

Rob

Thanks Rob for your detailed answer, but I still don’t get this thing working… :mellow:

Do you maybe have some fragments of sample code or a link to a tutorial for this topic, how I start such a MVC and which different cases I have to look at…where to settle onRowRender() and onRowTouch().

would be great again,

thx pepew

Look at this sample app:

https://github.com/coronalabs/samples-coronasdk/tree/master/Interface/WidgetDemo

It’s also installed as part of the product install in SampleCode/Interface/WidgetDemo off of the app’s install.

Rob

There is a programming paradigm called “Model-View-Controller” or MVC.   To simplify this, your view is your tableView, your model (i.e. the database) would be a simple Lua table holding the strings and the controller is the logic to draw the tableView (the onRowRender() function of the tableView.

That will handle filling out the table and getting it on screen.

Your input field can either stay at the top, and you can use the tableView’s onRowTouch() to set a flag about which field the input goes to and then put the data entered into the lua table and then insert the data into the row.

This is pretty straight forward, but it’s a bit of work. Your logic for dealing with the table view needs to know if you’re inserting a new row or updating one.  If you touch a row with data in it, then you probably should prepopulate a native.newTextField.

As a design decision, you can keep the field at the top or when someone taps a row, you draw a native.newTextField() over top of the row pre-populate it with the value of that row, and when the row is submitted, hide the keyboard put the text back in the row and get rid of the newTextInput().

Rob

Thanks Rob for your detailed answer, but I still don’t get this thing working… :mellow:

Do you maybe have some fragments of sample code or a link to a tutorial for this topic, how I start such a MVC and which different cases I have to look at…where to settle onRowRender() and onRowTouch().

would be great again,

thx pepew

Look at this sample app:

https://github.com/coronalabs/samples-coronasdk/tree/master/Interface/WidgetDemo

It’s also installed as part of the product install in SampleCode/Interface/WidgetDemo off of the app’s install.

Rob