iOS Question ListView with 2 Columns

Declan

Well-Known Member
Licensed User
Longtime User
I have an Android app developed with B4A.
I am currently porting this app over to iOS with B4i.
My B4A app uses a 2 column ListView as follows:
Create the ListView:
B4X:
    lstQuerySP1.TwoLinesLayout.ItemHeight = 25dip
    lstQuerySP1.TwoLinesLayout.Label.Top = 0
    lstQuerySP1.TwoLinesLayout.Label.Left = 0
    lstQuerySP1.TwoLinesLayout.Label.Width = 60%x
    lstQuerySP1.TwoLinesLayout.Label.Height = 28dip
    lstQuerySP1.TwoLinesLayout.Label.Gravity = Gravity.CENTER_VERTICAL
    lstQuerySP1.TwoLinesLayout.Label.Color = Colors.white
    lstQuerySP1.TwoLinesLayout.Label.TextColor = Colors.Black
    lstQuerySP1.TwoLinesLayout.Label.TextSize = 10
   
    lstQuerySP1.TwoLinesLayout.SecondLabel.Top = 0
    lstQuerySP1.TwoLinesLayout.SecondLabel.Left = 60%x
    lstQuerySP1.TwoLinesLayout.SecondLabel.Width = 40%x
    lstQuerySP1.TwoLinesLayout.SecondLabel.Height = 28dip
    lstQuerySP1.TwoLinesLayout.SecondLabel.Gravity = Gravity.CENTER_VERTICAL
    lstQuerySP1.TwoLinesLayout.SecondLabel.Color = Colors.white
    lstQuerySP1.TwoLinesLayout.SecondLabel.TextColor = Colors.Black
    lstQuerySP1.TwoLinesLayout.SecondLabel.TextSize = 10

Populate the List View from a local SQLite database:
B4X:
Sub ShowSalesBasketSummary
    Dim cursor1 As Cursor
    Dim txt As String
   
    lstQuerySP1.clear
   
    txt = "SELECT [Todays Sales] AS TOTALSALES, [Number Of Items Bought] AS NUMITEMSSOLD, [Number Of Sales] AS NUMOFSALES,  [Average Basket Total] AS AVBASKETTOT, [Items Per Basket] AS BASKETITEMS, [Total Cost] AS TOTALCOST, [Gross Profit %] AS GP, [My Price Conversion Rate] AS PCRATE, [Foot Count %] AS FOOTCOUNT FROM tableSP1"
    cursor1=SQL1.ExecQuery(txt)
    For i=0 To cursor1.RowCount-1
        cursor1.Position=i
        Dim MY_TOTALCOST As String = NumberFormat2(cursor1.GetDouble("TOTALCOST"), 1,2, 2,True)
        Dim MY_NUMOFSALES As String =  NumberFormat2(cursor1.GetDouble("NUMOFSALES"), 1,2, 0,True)
        Dim MY_NUMITEMSSOLD As String =  NumberFormat2(cursor1.GetDouble("NUMITEMSSOLD"), 1,2, 0,True)
        Dim MY_TOTALSALES As String = NumberFormat2(cursor1.GetDouble("TOTALSALES"), 1,2, 2,True) 
        Dim MY_AVBASKETTOT As String = NumberFormat2(cursor1.GetDouble("AVBASKETTOT"), 1,2, 2,True)  
        Dim MY_BASKETITEMS As String = NumberFormat2(cursor1.GetDouble("BASKETITEMS"), 1,2, 2,True)
        Dim MY_GP As String = NumberFormat2(cursor1.GetDouble("GP"), 1,2, 2,True)
        Dim MY_PCRATE As String = NumberFormat2(cursor1.GetDouble("PCRATE"), 1,2, 2,True)   
        Dim MY_FOOTCOUNT As String = NumberFormat2(cursor1.GetDouble("FOOTCOUNT"), 1,2, 2,True)

        lstQuerySP1.Clear
        lstQuerySP1.AddTwoLines(" Total Sales" , MY_TOTALSALES)
        lstQuerySP1.AddTwoLines(" Number Of Sales" , MY_NUMOFSALES)
        lstQuerySP1.AddTwoLines(" Number Of Units Sold" , MY_NUMITEMSSOLD)
        lstQuerySP1.AddTwoLines(" Average Sales per Basket" , MY_AVBASKETTOT)
        lstQuerySP1.AddTwoLines(" Average Items per Basket" , MY_BASKETITEMS)
        lstQuerySP1.AddTwoLines(" Total Cost of Sales" , MY_TOTALCOST)
        lstQuerySP1.AddTwoLines(" Gross Profit %" , MY_GP)
        lstQuerySP1.AddTwoLines(" My Price Conversion Rate" , MY_PCRATE)
        lstQuerySP1.AddTwoLines(" Foot Count %" , MY_FOOTCOUNT)

    Next
End Sub

Sorry for the "long-winded" explanation above, but how can I implement the same in B4i?
I have looked at CustomListView class and iTableView library, but can't seem to workout how to implement my original B4A code.
 

Declan

Well-Known Member
Licensed User
Longtime User
Can you post a screenshot of the B4A app?
I have attached the screen shot.
The "Top" grid is the 2 Colum ListView.
The "Bottom" grid is a Table, created as follows:
B4X:
    pnlTable.Initialize("")
    Activity.AddView(pnlTable, 0dip, 0dip, 100%x, 100%y )
    pnlTable.Height = 100%y   

    Table1.Initialize(Me, "Table1", 15, Gravity.CENTER_HORIZONTAL, False)
   
          Dim tf() As Typeface
            tf = Array As Typeface(Typeface.DEFAULT, Typeface.DEFAULT, Typeface.DEFAULT, Typeface.DEFAULT, Typeface.DEFAULT,Typeface.DEFAULT, Typeface.DEFAULT, Typeface.DEFAULT, Typeface.DEFAULT, Typeface.DEFAULT,Typeface.DEFAULT, Typeface.DEFAULT, Typeface.DEFAULT, Typeface.DEFAULT, Typeface.DEFAULT)
            Table1.SetTypeFaces(tf)

    Table1.CellAlignment = Bit.Or(Gravity.LEFT, Gravity.CENTER_VERTICAL)
    Table1.HeaderColor = Colors.Black
    Table1.HeaderTextColor = Colors.White
    Table1.TextColor = Colors.Black
    Table1.TableColor = Colors.DarkGray
    Table1.RowHeight = 30dip
   
    Table1.AddToActivity(pnlTable, 0, 0, pnlTable.Width, pnlTable.Height)   
'    Table1.MultiSelect = True
    Table1.MultiSelect = False
    Table1.SortColumn = False
    Table1.SingleLine = False
   
    Table1.Height = 600%y
    Table1.Width = 300%x
    Table1.Top = (pnlQuery.Top + pnlQuery.Height)- 55
    Table1.LineWidth = 1dip
    Table1.TextSize = 10
and populated from a local SQLite db.
 

Attachments

  • 160424102000.png
    160424102000.png
    104.5 KB · Views: 355
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Code:
B4X:
Private Sub Application_Start (Nav As NavigationController)
   NavControl = Nav
   Page1.Initialize("Page1")
   Page1.Title = "Page 1"
   Page1.RootPanel.LoadLayout("1")
   NavControl.ShowPage(Page1)
   For i = 1 To 30
     CustomListView1.Add(CreateItem("Item " & i, NumberFormat(Rnd(0, 100000) / 7, 3, 5)), ItemHeight, "")
   Next
End Sub

Private Sub CreateItem (Text1 As String, Text2 As String) As Panel
   Dim p As Panel
   p.Initialize("")
   p.SetLayoutAnimated(0, 1, 0, 0, 100%x, ItemHeight)
   p.LoadLayout("Item")
   Label1.Text = Text1
   Label2.Text = Text2
   Return p
End Sub

See the attached example.
 

Attachments

  • CustomListViewWith2Columns.zip
    6.3 KB · Views: 236
Upvote 0
Top