iOS Question Customize first and second line text size or line height of TableView

sdesan

Member
Licensed User
Longtime User
I need, as i made in b4a, to customize first and second line text size or line height of list view, pass a value to retrieve on click event and then open a file. Starting from b4a code

B4X:
'B4A code
Sub Globals
   Dim lstTracce As ListView
End Sub

Sub Activity_Create(FirstTime As Boolean)
  lstTracce.TwoLinesLayout.Label.TextSize = 14
  lstTracce.TwoLinesLayout.Label.Height = 60dip
  lstTracce.TwoLinesLayout.Label.Top=0
  lstTracce.TwoLinesLayout.SecondLabel.Top = lstTracce.TwoLinesLayout.Label.Height
  lstTracce.TwoLinesLayout.SecondLabel.TextSize = 12
  lstTracce.TwoLinesLayout.SecondLabel.Height = 40dip
  lstTracce.TwoLinesLayout.ItemHeight = lstTracce.TwoLinesLayout.Label.Height + lstTracce.TwoLinesLayout.SecondLabel.Height
  i = 0
  Do While i <7
    i = i+1
    lstTracce.AddTwoLines2(i,10+i,50+i)
  Loop
  lstTracce.SetSelection(0)
End Sub

Sub LstTracce_ItemClick (Position As Int, Value As Object)
   Dim selection As String
   Dim i As Intent
   selection ="file_" & Value & ".txt"
   If File.Exists(File.DirRootExternal, "/scabr/" & selection ) = False Then
       File.Copy(File.DirAssets, selection, File.DirRootExternal, "/scabr/" & selection )
   End If
   i.Initialize(i.ACTION_VIEW, "file://" & File.Combine(File.DirRootExternal, "/scabr/" & selection ))
   i.SetType("text/xml")
  Try
   StartActivity(i)
  Catch
   ToastMessageShow("Unable to open file.", True)
  End Try
End Sub

i write this code

B4X:
'b4i code
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'Public variables can be accessed from all modules.
   Public App As Application
   Public NavControl As NavigationController
   Public lstTracce As TableView
End Sub

Sub MyButton_Click
   main1.Initialize("main1")
   main1.Title = "My app"
   main1.RootPanel.LoadLayout("main")
   main1.RootPanel.AddView(lstTracce,0, 120, 100%x, 50%y)
   NavControl.ShowPage(main1)
   For i= 0 to 6
         lstTracce.AddTwoLines(i,10+i)
    Next
    lstTracce.ReloadAll
End Sub

Sub LstTracce_SelectedChanged (SectionIndex As Int, Cell As TableCell)
   Dim selection As String
   selection ="file_" & Cell.Text.ToString & ".txt"
   Try
     Msgbox(selection ," File to open ")
  'StartActivity(i)
  Catch
    Msgbox("Unable to open file.", "Error")
  End Try
End Sub

But in this way i need to name txt file (or fill TableView) with same name of file, but it will be more efficent to pass a value like in AddTwoLines2 on b4a
Last problem: TableView is not word-wrapp capable so i'm looking to this custom list view class but i have not find a good way.
Any help will be appreciated
 
Last edited:

sdesan

Member
Licensed User
Longtime User
Thank you Erel,
it works fine. I have also used this sub from Mashiane simply for uniformity whit b4a code using lstTracce.AddTwoLines2(i,10+i,50+i)
I have also set row height with
B4X:
lstTracce.RowHeight=20%y
but i still no find how to set multiline properties or wordwrap in cells
I keep studying ..
 
Upvote 0

sdesan

Member
Licensed User
Longtime User
Thanks again Erel,
i addedd
B4X:
...
For i= 0 to 6
   Dim tc As TableCell = lstTracce.AddTwoLines(i,10+i)
   tc.Tag=50+i
   tc.ShowSelection = False
   tc.CustomView = CreateItem
Next
 lstTracce.ReloadAll
...
Private Sub CreateItem As Panel
   Dim p As Panel
   p.Initialize("")
   p.Width = 100%x
   p.Height = lstTracce.RowHeight
   p.LoadLayout("showdata")
   Return p
End Sub

And on layout showdata i put two label with all desired changes (multiline, alignment, font ecc.)
Perfect.
Now i'm unable to find the way to pass value i and 10+i (or a more complex text) to two label i've inserted in showdata layout, I perceive to be simple but the solution eludes me
 
Upvote 0

sdesan

Member
Licensed User
Longtime User
Thanks Erel i solved using CustomListView (by mistake I deleted the previous post that still did not provide useful information) in this way
B4X:
...
Dim clv1 As CustomListView
...
...
For i= 0 to 6
   clv1.Add(CreateListItem(i, 10+i, clv1.GetBase.Width, 10%y), 30%y, 20+i)
Next
...
Sub CreateListItem(Text As String, Text2 As String, Width As Int, Height As Int) As Panel
   Dim p As Panel
   p.Initialize("")
   p.Color = Colors.Black
   Dim lbl,lbl2 As Label
   lbl.Initialize("lbl")
   lbl.TextAlignment = lbl.ALIGNMENT_CENTER
   lbl.Multiline= (True)
   lbl.Text = Text
   lbl.TextColor=Colors.White
   lbl.Font = Font.CreateNew(18)
   lbl2.Initialize("lbl2")
   lbl2.TextAlignment = lbl2.ALIGNMENT_LEFT
   lbl2.Multiline= (True)
   lbl2.TextColor=Colors.White
   lbl2.Text = Text2
   lbl2.Font = Font.CreateNew(16)
   p.AddView(lbl,0,0, 100%x, 10%y)
   p.AddView(lbl2, 0, 10%Y-5dip, 100%x, 20%Y)
   Return p
End Sub

Sub clv1_ItemClick (Index As Int, Value As Object)
   Try
    Msgbox(value," Value passed")
  Catch
    Msgbox("No data", "Errore")
  End Try
End Sub

and whit this the subject i think is closed, hoping to be helpful to someone else like me who is making porting from B4A to b4i.
Thank you again
 
Last edited:
Upvote 0
Top