Hi, I want to introduce my new extension which allows to create components dynamically! BUT;
You may ask;
There is an already bunch of different Dynamic Components extension, why did you created another one?
Because this one is different!
Everything starts from here:
It uses Java’s Reflection feature, so this allows you to create ANY component you want dynamically which added to App Inventor. Not only a
Button, you can even create a
DatePicker dynamically. Just type the component’s name which you want to create, that’s it!
What is reflection and how does it work?
Reflection (in programming) allows you to modify the program during runtime, for example you can create a new Class, Method etc. and search them by its names!
Basically, it appends
componentName parameter to the
com.google.appinventor.components.runtime. text and creates an instance of it. When you type “Button”, it searches for Button class and creates an instance of it.
So with this method it is now a fully implemented dynamic component extension.
I must say Java is a powerful language
I actually thought about a full method to create all dynamic components without creating different blocks for every component, but it would be useless. So I was trying to find a proper solution for a long time. And here it is!
Creating a dynamic component
See how it is easy to create any dynamic component. Just type the name of component which you want to create, give an ID for later use, specify a container which component will be placed in and done!
How about properties?
I knew that every component has different properties, so instead of creating methods for setting properties, I gave this job to “Any Component” blocks. This is much simplier to use. And it has events like “when any Button is clicked”.
This extension requires adding a static component to the Screen, otherwise you won’t able to access the Any Component blocks.
For example; when you want to use Any Button blocks, just add a Button to designer and make it invisible.
SetPropertyblock has a issue with different variable types. I’m aware of it and I recommend using Any Component blocks until it fixed.
Download from here!
com.yusufcihan.DynamicComponents.aix (12.7 KB)
You can post in topic for help, question about this extension or PM me anything about you want to talk!
- Yusuf Cihan