Android: How to find views by type

You can safely cast your result view to ViewGroup if you know that your layout's root element is any subclass like LinearLayout or other Layouts:

ViewGroup vg = (ViewGroup)view;

and use as you want. If you know that you will always use only one type of layout for root container, you can cast to that type, i.e.:

LinearLayout vg = (LinearLayout)view;

This should get you on the right track.

LinearLayout rootLinearLayout = (LinearLayout) findViewById(R.id.rootLinearLayout);
int count = rootLinearLayout.getChildCount();
for (int i = 0; i < count; i++) {
    View v = rootLinearLayout.getChildAt(i);
    if (v instanceof LinearLayout) {
        ...
    }
}