Android Question Input dispatching timed out

samannnn

Member
i have ANR in google play console:

project.xmsgbx._settextcustomsize
Input dispatching timed out

my code is :
B4X:
Sub SetTextCustomSize(lbl As Label, txt As String) As Int

    Dim dt As Float
    Dim limit = 0.5 As Float
    Dim h As Int
    Dim pad() As Int = lbl.Padding
 
    Dim TopPadding As Int    = pad(1)
    Dim BottomPadding As Int = pad(3)
    Dim LeftPadding As Int   = pad(0)
    Dim RightPadding As Int  = pad(2)
 
    Dim TotalToExclude As Int = (TopPadding + BottomPadding + (LeftPadding/2 )+ (RightPadding /2) )
 
 
    lbl.TextSize = 11
    dt = lbl.TextSize
    h = mStringUtils.MeasureMultilineTextHeight( lbl, txt) + TotalToExclude
    Do While dt > limit Or h > lbl.Height
        dt = dt / 2
        h = mStringUtils.MeasureMultilineTextHeight(lbl, txt) + TotalToExclude
        If h > lbl.Height Then
            lbl.TextSize = lbl.TextSize - dt
        Else
            lbl.TextSize = lbl.TextSize + dt
        End If
    Loop
    Return  lbl.TextSize
End Sub

i know problem is related to do while, how can i correct it?
my code is related to custom msgbox: https://www.b4x.com/android/forum/t...s-please-provide-your-feedback.92614/#content
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
B4X:
Dim retries As Int = 10
Do While retries > 0 and (dt > limit Or h > lbl.Height)
        retries = retries - 1
        dt = dt / 2
        h = mStringUtils.MeasureMultilineTextHeight(lbl, txt) + TotalToExclude
        If h > lbl.Height Then
            lbl.TextSize = lbl.TextSize - dt
        Else
            lbl.TextSize = lbl.TextSize + dt
        End If
    Loop
 
Upvote 0
Top