StringUtils error Layout: -1 < 0

barx

Well-Known Member
Licensed User
Longtime User
Trying to use StringUtils to measure text height and adjust height of a label as required. I get an error on the red Line. Can anybody see why? My code that is concerned with this function appears to match the example in the tool tip. The error shown is below.

lblDetail.Height = su.MeasureMultilineTextHeight(lblDetail, lblDetail.Text)

B4X:
Sub AddCheckBoxItem(Title As String, CheckedDetail As String, UncheckedDetail As String, Checked As Boolean)
   Dim P As Panel
   Dim lblTitle, lblDetail As Label
   Dim chkBox As CheckBox
   Dim su As StringUtils
   
   P.Initialize("Preference")
   svPreferences.Panel.AddView(P, 0, svPosition, (svPreferences.Panel.Width - 48dip), ItemHeight)
   P.Tag = Title
   
   lblTitle.Initialize("")
   lblTitle.Text = Title
   P.AddView(lblTitle, 10dip, 10dip, (svPreferences.Panel.Width - 48dip), 30dip)
   lblTitle.Tag = "Title"
   
   lblDetail.Initialize("")
   If Checked = True Then
      lblDetail.Text = CheckedDetail
   Else
      lblDetail.Text = UncheckedDetail
   End If
   P.AddView(lblDetail, 10dip, 40dip, svPreferences.Panel.Width, 30dip)
   lblDetail.Height = su.MeasureMultilineTextHeight(lblDetail, lblDetail.Text)
   lblDetail.Tag = "Detail"
   
   chkBox.Initialize("ChkBox")
   P.AddView(chkBox, P.Width - 20dip - 48dip, lblTitle.Top, 48dip, 48dip)
   chkBox.Tag = "Check"
   
   If (lblTitle.Height + lblDetail.Height + 4dip) > ItemHeight Then
      P.Height = lblTitle.Height + lblDetail + 4dip
   End If
End Sub

B4X:
java.lang.IllegalArgumentException: Layout: -1 < 0

Any info welcomed

Thanks
 

barx

Well-Known Member
Licensed User
Longtime User
Scrollview is added in designer layout. So should be auto initialized. Do I still need to initialize the inner panel. Will try it later.

Cheers tds

Sent from my HTC Desire Z
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User
Hi margret, thanks for taking a look and bringing up your findings.

The CheckedDetail and UnCheckedDetail are passed as arguments when the sub is called. I checked the debug info and the lblDetail.text does indeed = the passed detail. So that bit is working fine.

The search continues...

Sent from my HTC Desire Z
 
Upvote 0

JonPM

Well-Known Member
Licensed User
Longtime User
I recently ran into this to. Do a Log on svPreferences.panel.width and also P.Width after their widths get set. One (or both) are set to -1, which causes the error with SU. The work around may be setting svPreferences.panel.width = svPreferences.width
 
Upvote 0

barx

Well-Known Member
Licensed User
Longtime User

Worked a treat.

:sign0098:
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…