Android Question DSNavigationDrawer Crashes with IME.AddHeightChangedEvent

Discussion in 'Android Questions' started by JohnC, Jul 24, 2018.

  1. JohnC

    JohnC Well-Known Member Licensed User

    If you download the DSNavigationDrawer sample "NavigationView1_0.zip" from the OP here:

    https://www.b4x.com/android/forum/t...nal-material-design-components.58893/#content

    Then add the IME library to the project.

    Then add this line to the "Globals" section:
    Code:
    Dim IME As IME        'keyboard
    Then add these two lines to the "Activity_Create" right after the "ToolBar.InitMenuListener" line:
    Code:
    IME.Initialize("IME")    'keyboard
    IME.AddHeightChangedEvent

    When you run the sample, you will get this critical error:
    Code:
    ** Activity (main) Create, isFirst = true **
    main_activity_create (java line: 
    367)
    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:4212)
        at android.view.ViewGroup.addView(ViewGroup.java:
    4065)
        at android.view.ViewGroup.addView(ViewGroup.java:
    4010)
        at android.view.ViewGroup.addView(ViewGroup.java:
    3986)
        at anywheresoftware.b4a.objects.IME.AddHeightChangedEvent(
    IME.java:119)
        at example.navigationview.main._activity_create(main.java:
    367)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:
    372)
        at anywheresoftware.b4a.BA.raiseEvent2(BA.java:
    191)
        at example.navigationview.main.afterFirstLayout(main.java:
    104)
        at example.navigationview.main.access$
    000(main.java:17)
        at example.navigationview.main$WaitForLayout.run(main.java:
    82)
        at android.os.Handler.handleCallback(Handler.java:
    739)
        at android.os.Handler.dispatchMessage(Handler.java:
    95)
        at android.os.Looper.loop(Looper.java:
    145)
        at android.app.ActivityThread.main(ActivityThread.java:
    5951)
        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:
    1399)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:
    1194)
        at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:
    115)
    java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child
    's parent first.
     
  2. Erel

    Erel Administrator Staff Member Licensed User

  3. Semen Matusovskiy

    Semen Matusovskiy Well-Known Member Licensed User

    Design Support is really great and very useful library,
    But there are obvious problems in communication with B4A core objects.
    For instance, I was not able to re-create DSNavigationDrawer on fly (between Activity_Create events).

    I think it will be fine, if B4A developers will assist to fix troubles and will make a library as 'official'
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    You need to first explain what is missing in jfeinstein sliding menu. It should be very simple to add an image at the top and make it look like DSNavigationDrawer.
     
  5. Semen Matusovskiy

    Semen Matusovskiy Well-Known Member Licensed User

    Personally I like custom components, but many Android users prefer 'native'. It's sad, but a fact.
     
  6. JohnC

    JohnC Well-Known Member Licensed User

    Hey Erel,

    First, I don't like that slidingmenu because it doesn't slide the menu out in the typical manner of other apps - it slides the existing activity out to the right to expose the menu instead of the typical method of the menu sliding out from the left *on top* of the existing activity.

    Second, it too crashes as reported in post #111 of that thread, that I just confirmed gives the same exact error message when used with IME.
    Code:
    Sub Globals
        
    'These global variables will be redeclared each time the activity is created.
        'These variables can only be accessed from this module.
        Dim sm As SlidingMenu
        
        
    Dim IME As IME        'keyboard
    End Sub

    Sub Activity_Create(FirstTime As Boolean)
        
    'Do not forget to load the layout file created with the visual designer. For example:
        'Activity.LoadLayout("Layout1")
        sm.Initialize("sm")
        
    Dim offset As Int = 100dip
        sm.BehindOffset = offset
        sm.Mode = sm.BOTH
        
    Dim lv1 As ListView
        lv1.Initialize(
    "lv1")
        
    For i = 1 To 10
            lv1.AddSingleLine(
    "Action "  & i)
        
    Next
        sm.SecondaryMenu.AddView(lv1, 
    00100%x - offset, 100%y)
        
    Dim b1, b2 As Button
        b1.Initialize(
    "b1")
        b2.Initialize(
    "b2")
        b1.Text = 
    "Button1"
        b2.Text = 
    "Button2"
        sm.Menu.AddView(b1, 
    10dip10dip100%x - offset - 20dip50dip)
        sm.Menu.AddView(b2, 
    10dip60dip100%x - offset - 20dip50dip)
        
        
    IME.Initialize("IME")    'keyboard
        IME.AddHeightChangedEvent
    End Sub

    Sub Activity_Resume

    End Sub

    Sub Activity_Pause (UserClosed As Boolean)

    End Sub

    Sub lv1_ItemClick (Position As Int, Value As Object)
        
    Log(Value)
        sm.HideMenus
    End Sub
    Sub Activity_KeyPress (KeyCode As Int) As Boolean
        
    If KeyCode = KeyCodes.KEYCODE_BACK And sm.Visible Then
            sm.HideMenus
            
    Return True
        
    End If
        
    Return False
    End Sub
    Sub B1_Click
        
    Log("b1_click")
        sm.HideMenus
    End Sub
    Sub B2_Click
        
    Log("b2 click")
        sm.HideMenus
    End Sub
    Code:
    Logger connected to: 1e542c85
    --------- beginning of system
    --------- beginning of main
    *** 
    Service (starter) Create ***
    ** 
    Service (starter) Start **
    ** 
    Activity (main) Create, isFirst = true **
    main_activity_create (java line: 
    389)
    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:4212)
        at android.view.ViewGroup.addView(ViewGroup.java:
    4065)
        at android.view.ViewGroup.addView(ViewGroup.java:
    4010)
        at android.view.ViewGroup.addView(ViewGroup.java:
    3986)
        at anywheresoftware.b4a.objects.IME.AddHeightChangedEvent(
    IME.java:119)
        at b4a.example.main._activity_create(main.java:
    389)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:
    372)
        at anywheresoftware.b4a.BA.raiseEvent2(BA.java:
    191)
        at b4a.example.main.afterFirstLayout(main.java:
    104)
        at b4a.example.main.access$
    000(main.java:17)
        at b4a.example.main$WaitForLayout.run(main.java:
    82)
        at android.os.Handler.handleCallback(Handler.java:
    739)
        at android.os.Handler.dispatchMessage(Handler.java:
    95)
        at android.os.Looper.loop(Looper.java:
    145)
        at android.app.ActivityThread.main(ActivityThread.java:
    5951)
        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:
    1399)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:
    1194)
        at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:
    115)
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    It works if you initialize IME before initializing SlidingMenu.
     
  8. JohnC

    JohnC Well-Known Member Licensed User

    If I also init and add the heightchange event of the IME before this line for the DSNavigationDrawer:

    Code:
    NavDrawer.Initialize2("NavDrawer"Activity, NavDrawer.DefaultDrawerWidth, NavDrawer.GRAVITY_START)
    It will also prevent the crashing, but now the activity is displayed as pure white - no views on it.

    Since the IME seems to have a conflict with two different NavDrawers, is there a possible bug in IME?

    I ask because I would rather use DSNavigationDrawer because it slides the navdrawer out from the left on top of the current activity the same way as most apps do. But the other SlidingMenu you mention doesn't do this.
     
  9. Semen Matusovskiy

    Semen Matusovskiy Well-Known Member Licensed User

    I added some statements (see attached file).
    IME.AddHeightChangedEvent creates a parent of Activity
    NavDrawer.Initialize2 creates a parent of view, which you pass as second parameter.
    So , at first it's necessary to execute IME.AddHeightChangedEvent. Then NavDrawer.Initialize2 with Activity.Parent as parameter.
     

    Attached Files:

    • Test.zip
      File size:
      111.4 KB
      Views:
      48
    Last edited: Jul 25, 2018
  10. Erel

    Erel Administrator Staff Member Licensed User

    AddHeightChanged adds a new parent view to the main activity view. Both libraries also add a new parent view so the order is important. It is not a bug.
     
  11. JohnC

    JohnC Well-Known Member Licensed User

    Thank you - thank worked!
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice