iOS Question Authomatic resize of tebleview

Marco Maria Vilucchi

Active Member
Licensed User
Longtime User
I have a strange problem.
I start a page pressing the button "SERVIZIO" (foto 1)
Now I have a tableview with 4 choice (foto 2)
The tableview is on a panel and log says:
TableViewServizi.Width 320
TableViewServizi.Height 480
serviziPNpanel1.Width 320 (this is the panel with the tableview)
Then I press "MANUTENZIONE" and I return on the prior page (foto 3)
Finally I press again "SERVIZIO" and I have foto 4
Tableview is resized and text does not enter on the line
Log says:
TableViewServizi.Width 128
TableViewServizi.Height 128
serviziPNpanel1.Width 320

I create tableview with this code....

B4X:
Sub SelezionaServizio
   TableViewServizi.Initialize("TableViewServizi", False)
   TableViewServizi.Color=Colors.Transparent
   serviziPNpanel1.AddView(TableViewServizi, 0, 0, 100%x, 100%y)   
   contarighe = 0
   waitForAnimation.Initialize("waitForAnimation", 500)
   waitForAnimation.Enabled = True
End Sub

Sub waitForAnimation_tick
   waitForAnimation.Enabled = False
   For i = 0 To Main.rows.size - 1
     Dim m As Map
     m = Main.rows.Get(i)
     TableViewServizi.RowHeight = 50 'must set RowHeight before adding custom views.
     Log("TableViewServizi.Width " & TableViewServizi.Width)
     Log("TableViewServizi.Height " & TableViewServizi.Height)
     Log("serviziPNpanel1.Width " & serviziPNpanel1.Width)
     Dim tc1 As TableCell = TableViewServizi.AddSingleLine("")
     tc1.ShowSelection = False
     tc1.CustomView = CreateItemSer

     Dim name As String = m.Get("t14ambitidescrizione")
     comamb = m.Get("t14ambiticodice")
     lbTSer.Text=name
     lbTSerCod.Text=comamb
     btTSer.BringToFront
     contarighe=contarighe+1
   Next
   Main.NavControl.ShowPage(PageX)
   If contarighe=0 Then
     Messaggio="Nessuna Struttura selezionata"
     Msgbox2("Msg",Messaggio,Main.TitoloMsg,Array("OK"))
   End If
End Sub

Private Sub CreateItemSer As Panel
   Dim p As Panel
   p.Initialize("")
   p.Width = 100%x
   p.Height = TableViewServizi.RowHeight
   p.LoadLayout("tser")
   p.Color=Colors.Transparent
   Return p
End Sub

Where is my mistake?
Thanks
Marco
 

Attachments

  • foto 1.PNG
    foto 1.PNG
    127.3 KB · Views: 138
  • foto 2.PNG
    foto 2.PNG
    62.8 KB · Views: 143
  • foto 3.PNG
    foto 3.PNG
    129 KB · Views: 134
  • foto 4.PNG
    foto 4.PNG
    57.1 KB · Views: 147

Erel

B4X founder
Staff member
Licensed User
Longtime User
If you are using B4i v4 then you can simplify this code:
B4X:
Sub SelezionaServizio
   TableViewServizi.Initialize("TableViewServizi", False)
   TableViewServizi.Color=Colors.Transparent
   serviziPNpanel1.AddView(TableViewServizi, 0, 0, 100%x, 100%y) 
   contarighe = 0
   Sleep(500) '<--- instead of the timer
   For i = 0 To Main.rows.size - 1
     Dim m As Map

In most cases such errors are related to usage of %x / %y outside of the page_resize event. This is a mistake.

Why aren't you adding the view with the designer? It will be simpler.
 
Upvote 0
Top