Two column ListView

tcgoh

Active Member
Licensed User
Longtime User
How do you code a 2 column Listview drawn from a Sqlite database, if I want to display Col1 and Col2 like a table. Its works for me on a single col;


DBUtils.Executelistview(SQL1,"select Col1 from Table " ,Null,0, ListViewpage3,False)

Thanks
 

klaus

Expert
Licensed User
Longtime User
The attached example code fills a two line ListView.
The first and second Label are positioned side by side.
B4X:
Sub Globals
    Dim lsvTest As ListView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    lsvTest.Initialize("lsvTest")
    Activity.AddView(lsvTest, 0, 0, 100%x, 100%y)
    lsvTest.TwoLinesLayout.ItemHeight = 40dip
    lsvTest.TwoLinesLayout.Label.Top = 0
    lsvTest.TwoLinesLayout.Label.Left = 0
    lsvTest.TwoLinesLayout.Label.Width = 50%x
    lsvTest.TwoLinesLayout.Label.Height = 40dip
    lsvTest.TwoLinesLayout.Label.Gravity = Gravity.CENTER_VERTICAL
    lsvTest.TwoLinesLayout.Label.Color = Colors.Red
    lsvTest.TwoLinesLayout.Label.TextSize = 18
    
    lsvTest.TwoLinesLayout.SecondLabel.Top = 0
    lsvTest.TwoLinesLayout.SecondLabel.Left = 50%x
    lsvTest.TwoLinesLayout.SecondLabel.Width = 50%x
    lsvTest.TwoLinesLayout.SecondLabel.Height = 40dip
    lsvTest.TwoLinesLayout.SecondLabel.Gravity = Gravity.CENTER_VERTICAL
    lsvTest.TwoLinesLayout.SecondLabel.Color = Colors.Blue
    lsvTest.TwoLinesLayout.SecondLabel.TextColor = Colors.Yellow
    lsvTest.TwoLinesLayout.SecondLabel.TextSize = 18

    For i = 0 To 100
        lsvTest.AddTwoLines("Test1" & i, "Test2" & i)
    Next
End Sub
Best regards.
 

Attachments

  • ListViewTwoColumns.zip
    5.7 KB · Views: 915
  • ListViewTwoColumns.jpg
    ListViewTwoColumns.jpg
    74.5 KB · Views: 2,043
Upvote 0

tcgoh

Active Member
Licensed User
Longtime User
Hi Klaus,

Thanks for the code.:icon_clap: But how does my SQL1 fit into this ?

DBUtils.Executelistview(SQL1,"select Col1 from Table " ,Null,0, ListViewpage3,twolines?)

Sorry I am a beginner. Thanks
 
Upvote 0

tcgoh

Active Member
Licensed User
Longtime User
Hi Klaus,

Thanks for the inputs. But now I'm stuck in the selection of a row(text or data) to be displayed on a label after a "_itemclick" event.

I'm not changing the first screen from ListView to Scrollview because after the itemClick event, I'll be openning up scrollView from the same database.

Looks like I have go back to Spinner which is very restrictive in display presentation!

Unless someone can show me how to declare a couple of variables to hold the result in GetView.


Thanks
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
You could use AddTwoLines2 where you can set the return value, for example a string array with the values of the two columns.
But for this you woukd need to either
- add a routine to the DBUtils module that adds the return value.
- write your own routine.

Sorry, but I don't really undestand the rest of your post.

Best regards.
 
Upvote 0
Top