Android Question Trying to resize a customlistview when the soft keyboard appears

patrick14384

Member
Licensed User
Longtime User
I have a customlistview that I want to resize when the soft keyboard appears, and I swear it was working finally after a couple of nights of struggling, but all of the sudden it stopped working and for the life of me I cannot figure out why. It crashes when it gets to End Sub for IME1_HeightChanged

The stack I get is
java.lang.IllegalStateException: This method must only be called as part of a callback while a frame is in progress.
at android.view.Choreographer.getFrameTimeNanos(Choreographer.java:471)
at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:310)
at android.view.ViewRootImpl.draw(ViewRootImpl.java:2530)
at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2352)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1982)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1061)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5885)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
at android.view.Choreographer.doCallbacks(Choreographer.java:580)
at android.view.Choreographer.doFrame(Choreographer.java:550)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

and for code I have
B4X:
Sub IME1_HeightChanged(NewHeight As Int, OldHeight As Int)
    Debugger("Entering IME_HeightChanged...")
    Dim intKeyboardSize As Int = Max(NewHeight, OldHeight) - Min(NewHeight, OldHeight)
    If NewHeight < OldHeight Then    ' Keyboard displayed
        'Debugger("CustomListView1.AsView.Tag:  " & CustomListView1.AsView.SetLayout(0, 0%y, 100%x, CustomListView1.AsView.Height - intKeyboardSize)
        CustomListView1.AsView.SetLayout(0, 0%y, 100%x, CustomListView1.AsView.Height - intKeyboardSize)
        'CustomListView2.AsView.SetLayout(0, CustomListView1.AsView.Height, 100%x, 10%y)
    Else                             ' Keyboard hidden
        CustomListView1.AsView.SetLayout(0, 0%y, 100%x, CustomListView1.AsView.Height + intKeyboardSize)
        'CustomListView2.AsView.SetLayout(0, CustomListView1.AsView.Height, 100%x, 10%y)
 
    End If
End Sub

CustomListView1 and CustomListView2 and IME1 are declared as global variables

B4X:
    <more code>
Dim UIInput As String
Dim YHeightTotal As Int
Dim YHeight As Int
Dim ActivityHeight As Int
Dim CustomListView1Height As Int
    
YHeight = 50dip
ActivityHeight = Activity.Height
   
'Add the first panel with the list of options and an input field for each
Activity.AddView(CustomListView1.AsView, 0, 0%y, 100%x, ActivityHeight-YHeight)
   
For i = 0 To CustomListDBFields.Size - 1
    'Assign the edtbox/button type for the view
    UIInput = CustomListDBUIInput.Get(i)
    'Add the view now
    CustomListView1.Add(CustomListView_CreateListItem(CustomListDBFields.Get(i),
        CustomListDBUnits.Get(i), CustomListView1.AsView.Width, _
        YHeight, UIInput, CustomListDBFields.Get(i), False), YHeight, CustomListDBFields.Get(i))
Next

CustomListView2.Initialize(Me, "CustomListView2")
   
CustomListView1Height = CustomListView1.AsView.Height
HeightFromBottom = ActivityHeight - (ActivityHeight - CustomListView1Height)

Activity.AddView(CustomListView2.AsView, 0, HeightFromBottom, 100%x, YHeight)

'Add the second panel, with the buttons to control the dialog
CustomListView2.Add(CustomListView_CreateButtonItem(YHeight),YHeight,"not sure")

I am hoping someone has a quick pointer for me.

Thanks,
Patrick
 

patrick14384

Member
Licensed User
Longtime User
Thanks RandomCoder, I had already looked at that post.

Sheer luck just led me to discover the issue. If I place a breakpoint in the sub IME1_HeightChanged then it will crash, but if I take the breakpoint out everything works just fine. So I am all set now.
 
Upvote 0
Top