Android Question Help!!! How can I populate table with arraylist

Peter Simpson

Expert
Licensed User
Longtime User
Hello,
I'm retrieving data from an MySQL database and the results are being placed into an List. My question is how can I get that data into a Table. I wrongly presumed by doing the following I would get line 1 from the List into the table: Table.AddRow(Array As String(List.Get(1))), but I was wrong :(

I keep getting the following error: "Wrong number of values". Example of the values are below.
[1677, PHI0065, 19 July 2013, Philomena Gardner, £46.85, Yes, Yes, Yes]

I actually want to populate a table. The first two results from the ArrayList are below, I do set the number of columns to 8 with the following line Table.Initialize(Me, "Test", 8).
(ArrayList) [[Invoice Number, Account Number, Invoice Date, Company Name, Total, Printed, Posted, Paid], [1685, INT0012, 19 July 2013, Intensa, £62.87, No, No, Yes], [1677, PHI0065, 19 July 2013, Philomena Gardner, £46.85, Yes, Yes, Yes]]

What I actually want is to get data from an MySQL database into a Table, and not into a ListView or ScrollView both of which I can already do.

Any example source code would be more than appreciated :)

Thank you...
 
Last edited:

Peter Simpson

Expert
Licensed User
Longtime User
Good morning Erel, yes you are correct, but I can't seem to get the string arrays to work with Table.Add. When I say table, I mean this table http://www.b4x.com/android/forum/th...upports-tables-of-any-size.19254/#post-110901

Log results of list arrays

ArrayList
(ArrayList) [[Invoice Number, Account Number, Invoice Date, Company Name, Total, Printed, Posted, Paid], [1685, INT0012, 19 July 2013, Intensa, £62.87, No, No, Yes], [1677, PHI0065, 19 July 2013, Philomena Gardner, £46.85, Yes, Yes, Yes], [1672, LUC0032, 19 July 2013, Lucy Profeta, £27.79, Yes, Yes, Yes], [1668, AME0007, 18 July 2013, Ameibein Limited, £65.31, Yes, Yes, Yes], [1646, CHA0062, 16 July 2013, Charles Edward Hill, £27.95, Yes, Yes, Yes], [1633, FAI0008, 14 July 2013, Faith Stevens, £18.85, Yes, Yes, Yes], [1632, KER0011, 14 July 2013, Kerstinkitchen, £147.38, Yes, Yes, Yes], [1631, SHI0012, 12 July 2013, Shirley Slimane, £34.45, Yes, Yes, Yes], [1619, MAR0302, 11 July 2013, Martin Prescott, £31.90, Yes, Yes, Yes], [1617, API0002, 11 July 2013, Apichanuch Sangrungrueng, £23.15, Yes, Yes, Yes]]

ArrayList to JSON
(JSONTokener) at character 0 of (ArrayList) [[Invoice Number, Account Number, Invoice Date, Company Name, Total, Printed, Posted, Paid], [1685, INT0012, 19 July 2013, Intensa, £62.87, No, No, Yes], [1677, PHI0065, 19 July 2013, Philomena Gardner, £46.85, Yes, Yes, Yes], [1672, LUC0032, 19 July 2013, Lucy Profeta, £27.79, Yes, Yes, Yes], [1668, AME0007, 18 July 2013, Ameibein Limited, £65.31, Yes, Yes, Yes], [1646, CHA0062, 16 July 2013, Charles Edward Hill, £27.95, Yes, Yes, Yes], [1633, FAI0008, 14 July 2013, Faith Stevens, £18.85, Yes, Yes, Yes], [1632, KER0011, 14 July 2013, Kerstinkitchen, £147.38, Yes, Yes, Yes], [1631, SHI0012, 12 July 2013, Shirley Slimane, £34.45, Yes, Yes, Yes], [1619, MAR0302, 11 July 2013, Martin Prescott, £31.90, Yes, Yes, Yes], [1617, API0002, 11 July 2013, Apichanuch Sangrungrueng, £23.15, Yes, Yes, Yes]]

Screen shot below.

Thank you...
 

Attachments

  • Untitled-1.png
    Untitled-1.png
    54 KB · Views: 261
Last edited:
Upvote 0

klaus

Expert
Licensed User
Longtime User
Try this code:
B4X:
Dim row() As String
row = Regex.Split(",", ResultList.Get(0))
Table2.SetHeader(row)
For i = 1 To ResultList.Size - 1
    row = Regex.Split(",", ResultList.Get(i))
    Table2.AddRow(row)
Next
Best regards.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Dim row() As String
dim strresult as string

row = Regex.Split(",", ResultList.Get(0))
Table2.SetHeader(row)
For i = 1To ResultList.Size - 1
strresult=ResultList.Get(I)
strresult=strresult.replace("[","").replace("]","")
row = Regex.Split(",", strresult)
Table2.AddRow(row)
Next
 
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
Thank you @Mahares. That basically looks like the way that I did it but I also included the header.

B4X:
           Dim Row As String
                Row = ResultList.Get(0)
            Table2.SetHeader(Regex.Split(", ", Row.Replace("[","").Replace("]","")))
     
            For I = 1 To ResultList.Size - 1
                Row = ResultList.Get(I)
                Table2.AddRow(Regex.Split(", ", Row.Replace("[","").Replace("]","")))
            Next

It's strange how coding works sometimes.
This has taken me a long time to get fully working correctly. But I created and released my first ever swipe menu library in just one day :)


Thanks again to everybody.
 
Last edited:
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
I did at first, but the [[...]] instead of {[...]} had me stumped, that why I then went for the solution above. Anyway, about an hour after my last post in this thread, I decided to stop using the MySQL library and started using HTTPUtils2 to connect to MySQL databases, thus I could then parse the results string with the JSON library, which is exactly what I done.

Cheers anyway Erel :)
 
Upvote 0
Top