Android Question IME library error

uniplan

Active Member
Licensed User
I have tried to use IME library but when I add the statement:

B4X:
IME.AddHeightChangedEvent

I have this error:

java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
at android.view.ViewGroup.addViewInner(ViewGroup.java:4326)
at android.view.ViewGroup.addView(ViewGroup.java:4162)
at android.view.ViewGroup.addView(ViewGroup.java:4103)
at android.view.ViewGroup.addView(ViewGroup.java:4076)
at anywheresoftware.b4a.objects.IME.AddHeightChangedEvent(IME.java:119)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:753)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:343)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:247)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at uniplan.map.frmmainautista.afterFirstLayout(frmmainautista.java:102)
at uniplan.map.frmmainautista.access$000(frmmainautista.java:17)
at uniplan.map.frmmainautista$WaitForLayout.run(frmmainautista.java:80)
at android.os.Handler.handleCallback(Handler.java:743)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:150)
at android.app.ActivityThread.main(ActivityThread.java:5665)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:822)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:712)
 

uniplan

Active Member
Licensed User
B4X:
Sub Activity_Create(FirstTime As Boolean)
   


    'Initialize the NavDrawer object. This modifies the internal Layout structure of your Activity
    'and adds the Navigationdrawer.
    'Attention: THIS HAS TO BE DONE BEFORE LOADING A LAYOUT TO THE ACTIVITY!
    NavDrawer.Initialize2("NavDrawer", Activity, NavDrawer.DefaultDrawerWidth, NavDrawer.GRAVITY_START)
    Activity.LoadLayout("frmMainAutista")

    creazione_action_bar_e_menu

    If FirstTime=True Then
        rsz.rszMAP.Initialize
        rsz.setta_scala(Activity)
        cnb.Initialize(Colors.LightGray,5)
        'spnAutomezzi.Background=cnb
        acspnAutomezzi.Background=cnb
        'spnAutomezzi.DropdownBackgroundColor=cnb
        'pgWheel1.Initialize("pgw")
        bg.Initialize(1000)
        timer_beacon.Initialize("timerBeacon",1000)
        timer_nota_vocale.Initialize("timer_nota_vocale",1000)
        timer_nota_vocaleODS.Initialize("timer_nota_vocaleODS",1000)
        avs.Initialize
        ods_attivo.Initialize
        man_str_attiva.Initialize
       
        imageFolder = Starter.rp.GetSafeDirDefaultExternal("")
        spmMANcatMap.Initialize
        lstViewMANelencoMAP.Initialize
        audioGest.Initialize("frmMainAutista","audioGest_esito")
        audioGestODS.Initialize("frmMainAutista","audioGestODS_esito")
       
        IME1.Initialize("IME1")
        IME1.AddHeightChangedEvent

    End If
   
    ridimensiona
   
End Sub
 
Upvote 0

Erel

Administrator
Staff member
Licensed User
Here is the solution:

Add this sub:
B4X:
Sub InitializeNavDrawerAndIME
   ime.Initialize("ime")
   ime.AddHeightChangedEvent
   Dim e As Panel = Activity.Parent
   e.RemoveAllViews
   Dim p As Panel = e.Parent
   p.RemoveAllViews
   p.AddView(Activity, 0, 0, 100%x, 100%y)
   'Initialize the NavDrawer object. This modifies the internal Layout structure of your Activity
   'and adds the Navigationdrawer.
   'Attention: THIS HAS TO BE DONE BEFORE LOADING A LAYOUT TO THE ACTIVITY!
   NavDrawer.Initialize2("NavDrawer", Activity, NavDrawer.DefaultDrawerWidth, NavDrawer.GRAVITY_START)
   p = Activity.Parent
   Dim p2 As Panel = p.Parent
   p.RemoveView
   p2.AddView(e, 0, 0, 100%x, 100%y)
   e.AddView(p, 0, 0, 100%x, 100%y)
End Sub

Call InitializeNavDrawerAndIME instead of the call to NavDrawer.Initialize2.
 
Upvote 0

JohnC

Expert
Licensed User
Upvote 0
Top