Bug? RerunDesignerScript in CustomView fails

corwin42

Expert
Licensed User
Longtime User
I'm trying to write a custom view which loads a layout file.

For customizing the view I will call RerunDesignerScript but I always get the error "cannot find view" and
"All views in script should be declared."

All views are declared in my custom view class.

I think the problem is that Activity.RerunDesignerScript() expects the variables to be declared in the activity and not in the class. Is it possible to call RerunDesignerScript() in a class module?

Attached is a simple project which shows the problem.
 

Attachments

  • RerunScriptError.zip
    11.6 KB · Views: 224

Erel

B4X founder
Staff member
Licensed User
Longtime User
The problem is that it looks for the views in the activity and not the class.

It cannot be fixed without updating the core library.

If you like you can create a small library with this code:
B4X:
public void RerunDesignerScriptFromClass(String Layout, BA ba, int Width, int Height) throws Exception {
     ViewGroup vg = new BALayout(ba.context);
     vg.setLayoutParams(new ViewGroup.LayoutParams(Width, Height));
     HashMap<String, ViewWrapper<?>> dynamicTable = new LayoutBuilder.LayoutHashMap<String, ViewWrapper<?>>();
     for (Field f : ba.eventsTarget.getClass().getFields()) {
       if (f.getName().startsWith("_") && ViewWrapper.class.isAssignableFrom(f.getType())) {
         dynamicTable.put(f.getName().substring(1), (ViewWrapper<?>) f.get(ba.eventsTarget));
       }
     }
     LayoutBuilder.loadLayout(Layout, ba, false, vg, dynamicTable, false);
   }
I haven't tested it.
 
Top