Android Question Save the data of a listview in a sqlite database and recall it to modify it when needed

fifiddu70

Well-Known Member
Licensed User
Longtime User
Hello everyone, after years of absence I come back to make myself heard with a question that I hope can be solved, I have an old application for managing orders that uses a listview where I insert the products, for example: 1: pizza Margherita - Euro 6.50
these are then sent to the thermal printer, but once sent to the printer I would like to be able to save them perhaps in a sqlite database and be able to recall them for example always by loading them into the listview and I would like to be able to modify them by adding or removing the individual products loaded into the listview with the relative price.
I post the code that I use to send the order, considering that I insert the contents of the listview and all the other elements into a text box, see example.
B4X:
For i = 0 To lswordine2.Size -1
txtlswordine2.Text = txtlswordine2.Text & lswordine2.GetItem(i) & CRLF
Log("verifico cosa contiene txtlswordine2.text con switchstampante = 0 " & txtlswordine2.Text)
Next
How can I save this listview and reopen it whenever I want to edit its content?
I managed to save the text boxes that are in the order sending app but I don't understand how to save the listview and its content, I attach a code example to save the data of the text boxes.
B4X:
 Dim NewID As Int
            Try
                NewID = SQL1.ExecQuerySingleResult("SELECT max(id) FROM listview ") + 1
            Catch
                NewID = 1
            End Try
       
            Dim qry As String
            Dim MyFields() As Object
            MyFields=Array As Object(txttavolo.Text,txtoperatore.Text,txteuro.Text,txttotaleeuro.Text ,txtnote.Text,NewID)
            qry = "INSERT INTO listview VALUES (?,?,?,?,?,?)"   'Account for all fields
            SQL1.ExecNonQuery2(qry,MyFields)
             txteuro.Text=""
            'txttotaleeuro.Text=""
            txtnote.Text=""
 
Last edited:

cklester

Well-Known Member
Licensed User
The database way to do it is have a LineItems table where you store line item information (from your ListView). Then you'll have a reference field (foreign key?) back to your Orders table.
 
Upvote 0

fifiddu70

Well-Known Member
Licensed User
Longtime User
The database way to do it is have a LineItems table where you store line item information (from your ListView). Then you'll have a reference field (foreign key?) back to your Orders table.
You have a little code example?
 
Upvote 0

cklester

Well-Known Member
Licensed User
No code, but it seems this is more a database schema issue than anything else.

It looks like you know how to construct databases, tables, and insert data. So, you just need to understand how to put that data into the database (how to structure the database) for easy storage and retrieval.

You'll have at least 4 tables: Customers, Items, LineItems, and Orders.

Customers is self-explanatory.

Each Order will have its own OrderID and be a record containing at least the Customer ID and DateAndTime.

Each LineItem will have its own LineItemID, and will have a reference to the OrderID of which it pertains and the relevant ItemID. You'd probably want to store price, discount, etc. for that particular item for that particular order.

If that doesn't make sense, then I hope somebody comes along with some relevant code for you! Otherwise, you get to do some research into optimal database schemas! 😁
 
Upvote 0
Top