Java Question Problem loading Layout into a Panel in Debug Mode

corwin42

Expert
Licensed User
Longtime User
I'm trying to load a Layout in a library to a panel. This is the code:

B4X:
    @BA.RaisesSynchronousEvents
    public MaterialDialogBuilderWrapper CustomView2(final String B4ALayout, final boolean WrapInScrollView, int Height) {
        final PanelWrapper panel = new PanelWrapper();
        panel.Initialize(mBa, "");
        mCustomViewHeight = Height;

        mBuilder.customView(panel.getObject(), WrapInScrollView);

        ViewTreeObserver viewTreeObserver = panel.getObject().getViewTreeObserver();
        if (viewTreeObserver.isAlive()) {
            viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    panel.getObject().getViewTreeObserver().removeGlobalOnLayoutListener(this);

                    panel.setHeight(panel.getObject().getMeasuredHeight());
                    panel.setWidth(panel.getObject().getMeasuredWidth());

                    try {
                        panel.LoadLayout(B4ALayout, mBa);
                    } catch (Exception e) {
                        e.printStackTrace();
                        BA.Log("Unable to load Layout");
                    }

                    MaterialDialogWrapper dialog = new MaterialDialogWrapper(mDialog, mBa, mEventName);
                    mBa.raiseEventFromUI(mDialog, mEventName + "_customviewready", dialog, panel);
                }
            });
        }

        return this;
    }

This works very well in release mode. In Debug mode the app just closes without any notice.

The unfiltered logs show the following:


Can I make this work in debug mode?

I have to use ViewTreeObserver because only at the onGlobalLayout event the correct sizes of the Panel are known.
 

corwin42

Expert
Licensed User
Longtime User
Ok, implemented it with the event so the layout is loaded into the panel in B4A code.
Additionally that avoids the problem that the B4A IDE warns about a not used layout file.

The library is getting quite awesome. I hope to get it ready next week.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…