Android Question cant add all the rows in table format

Shripal Dalal

Member
Licensed User
Longtime User
A much improved version is available here.

You can use the code in this example to show data in tabular form.

table_1.png


The table is made of two main views. The header row is made of a panel with labels. The main cells component is made of a ScrollView with labels as the cells.

You can modify the code to change the table appearance.
Some of the settings can be changed in Sub Globals:
B4X:
    'Table settings
    HeaderColor = Colors.Gray
    NumberOfColumns = 4
    RowHeight = 30dip
    TableColor = Colors.White
    FontColor = Colors.Black
    HeaderFontColor = Colors.White
    FontSize = 14
Adding data to the table:
B4X:
    'add header
    SetHeader(Array As String("Col1", "Col2", "Col3", "Col4"))
    'add rows
    For i = 1 To 100
        AddRow(Array As String(i, "Some text", i * 2, "abc"))
    Next
    'set the value of a specific cell
    SetCell(0, 3, "New value")
    'get the value
    Log("Cell (1, 2) value = " & GetCell(1, 2))
Table events:
B4X:
Sub Cell_Click
    Dim rc As RowCol
    Dim l As Label
    l = Sender
    rc = l.Tag
    activity.Title = "Cell clicked: (" & rc.Row & ", " & rc.Col & ")"
End Sub
Sub Header_Click
    Dim l As Label
    Dim col As Int
    l = Sender
    col = l.Tag
    Activity.Title = "Header clicked: " & col
End Sub
The code is not too complicated and you can further customize it as needed.




i am using this above code to bind my csv data, but it is adding only 1st row in table and does not iterate loop 2nd time.

can any1 point out that am i making any mistake in my code?
below is my code

B4X:
Dim list1,list2 As List
list1.Initialize()
list2.Initialize()

SetHeader(Array As String("No.", "Location", "Mrp", "Disc", "TotalAmt"))

    list1=sf.Split(strGlobalReportString, "~")             '' splitting rows
            For i=0 To list1.Size-1
                list2=sf.split(list1.Get(i), "!")                 '' splitting columns of individual row
                If list2.Size > 0 Then
                   AddRow(Array As String(i, list2.Get(0), list2.Get(1), list2.Get(2),list2.Get(3)))
               End If
            Next
 
Last edited:

klaus

Expert
Licensed User
Longtime User
How do you read the csv file?
Do you use the LoadCsv or LoadCsv2 method from the StringUtils library ?

The Flexible Table class includes a routine to import csv files into the table.
 
Last edited:
Upvote 0

Shripal Dalal

Member
Licensed User
Longtime User
How do you read the csv file?
Do you use the LoadCsv or LoadCsv2 method from the StringUtils library ?

The Flexible Table class includes a routine to import csv files into the table.






what i am doing is:- I get results in single line from sql as follows:
1!x!y!z~2!a!b!c~

so i am splitting the columns(~) then after rows (!)
i use for loop and it works fine in all other forms with lisview controls.
but here i am adding it in array as string and that is fetching only 1st row.
B4X:
list1=sf.Split(strGlobalReportString, "~")             '' splitting rows
            For i=0 To list1.Size-1
                list2=sf.split(list1.Get(i), "!")                 '' splitting columns of individual row
                If list2.Size > 0 Then
                  ''listviewSummary.AddTwoLines2(list2.Get(0),list2.Get(1),list2.Get(0))
                   AddRow(Array As String(i, list2.Get(0), list2.Get(1), list2.Get(2),list2.Get(3)))
               End If
            Next
 
Upvote 0

Shripal Dalal

Member
Licensed User
Longtime User
Maybe you mean "last Row"!?


i meant 1st row i.e: 1!x!y!z out of 1!x!y!z~2!a!b!c~

i moved the dim of list2 inside the loop
loop executes only once. it adds row in table and then it goes out of loop even though there are 2 records.
actually loop should execute twice but it doesn't and That is the main problem.:(
 
Upvote 0

Shripal Dalal

Member
Licensed User
Longtime User
hey guys i solved the problem.

I did thorough debugging and tried "j" instead of "i" as counter in loop and it worked.
B4X:
For j=0 To list1.Size-1
rest of the things are working fine as expected. splitting function is also fine without any problem.

thank you all for the suggestions & help.:)
 
Upvote 0
Top