I need to access the children controls of a parent control. The code i am using is:
for (int index = 0; index <= parent.getChildCount() - 1; index++)
{
Log.d("myTag", parent.getChildAt(index).toString());
}
It works fine however i was looking for something like:
foreach(control ctl in parentControl.Children)
{
Log.d("myTag", ctl.toString());
}
Thanks in advance for your valuable time & help.
Since you can only access the children of a view using the method
getChildAt(), you won’t be able to use it in such a foreach loop.However, if you really want it, you could make a list of the children, then iterate over it this way:
(Thats the syntaxs of
foreachloop in java)But it’s not needed and you will be wasting time and memory doing so. Just use the
forloop.