Is it possible to get children component list of an arrangement?

Hi there.
Is it possible to get children component list of an arrangement by Java/extension?
So that i can use the any component block to manipulate item of the list.

At the moment containers don't actually keep track of their child components, but it should be possible in the next release as it adds a getChildren() method to ComponentContainer. You can sort of hack it if you use Java reflection to extract the list of all components, and then for every component that extends AndroidViewComponent use reflection to gets it container field and filter for the target container.


here is the code -

HVArrangement container;
final View v = container.getView();
FrameLayout frameLayout = (FrameLayout) v;
List<View> views = new ArrayList<View>();
final int childCount = frameLayout.getChildCount();
for (int i = 0; i < childCount; i++) {
      View vi = ll.getChildAt(i);
1 Like

Thanks and waiting next release

1 Like

Have you test it? This list will get a java native view, not app inventor component.

well i could have only found this i will do more research

I have tried this:


public List ChildreList(HVArrangement component) {
List childrenList = new ArrayList();
ViewGroup subGroup = (ViewGroup) ((ViewGroup) component.getView()).getChildAt(0);
for (int i = 0; i < subGroup.getChildCount(); i++) {
return childrenList;

and I got this:

but I want to get like this:

1 Like

View and AndroidViewComponent are different.


idk but will assigning like this will work ? -

android.widget.Button androidButton; appinventorButton = ( androidButton;
1 Like

Don't think widget Button can be casted to ai component Button.


No. The two classes have no common ancestors (except java.lang.Object). Casting of that nature is safe if you're casting to a superclass/superinterface of the instance's type, and it's unsafe if you cast down to a known subclass of the type, but in this case it is illegal because there's no relationship between the two types. You'll likely get an error from the Java compiler to this effect.


maybe this topic helps - Converting a view to AndroidViewComponent

1 Like

I basically say the same thing in that thread as I am saying in this one. You cannot cast from one type to the other because they have no common ancestry in the class hierarchy.

1 Like