Example usage for android.view ViewGroup getChildAt

List of usage examples for android.view ViewGroup getChildAt

Introduction

In this page you can find the example usage for android.view ViewGroup getChildAt.

Prototype

public View getChildAt(int index) 

Source Link

Document

Returns the view at the specified position in the group.

Usage

From source file:Main.java

public static void setupTypeface(View view, Typeface globalFace) {
    try {//  w ww. j  av  a 2s .  c o m
        if (view instanceof EditText) {
            ((EditText) view).setTypeface(globalFace);
        } else if (view instanceof CheckBox) {
            ((CheckBox) view).setTypeface(globalFace);
        } else if (view instanceof TextView) {
            ((TextView) view).setTypeface(globalFace);
            //((TextView) view).setLineSpacing(getPixelsFromDp(1f), 1f);
        } else if (view instanceof ViewGroup) {
            ViewGroup vg = (ViewGroup) view;
            for (int i = 0; i < vg.getChildCount(); i++) {
                View child = vg.getChildAt(i);
                setupTypeface(child, globalFace);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

private static int calculateParallaxLayersRecursively(View view, int count) {
    if (view instanceof ViewGroup) {
        ViewGroup group = (ViewGroup) view;
        for (int i = 0; i < group.getChildCount(); i++) {
            count = calculateParallaxLayersRecursively(group.getChildAt(i), count);
        }/*from  ww  w.  java 2 s .c  om*/
    } else {
        count++;
    }
    return count;
}

From source file:Main.java

public static <X extends View> X getChild(ViewGroup row, Class<X> klass) {
    assert klass != null;
    for (int i = 0; i < row.getChildCount(); i++) {
        View child = row.getChildAt(i);
        if (klass.isAssignableFrom(child.getClass())) {
            return klass.cast(child);
        }//from   w  ww . jav  a  2  s. c o  m

        if (child instanceof ViewGroup) {
            X kid = getChild((ViewGroup) child, klass);
            if (kid != null)
                return kid;
        }
    }
    // fail
    return null;
}

From source file:Main.java

private static int calculateParallaxLayersRecursively(View view, int startCount) {
    int count = startCount;
    if (view instanceof ViewGroup) {
        ViewGroup group = (ViewGroup) view;
        for (int i = 0; i < group.getChildCount(); i++) {
            count = calculateParallaxLayersRecursively(group.getChildAt(i), count);
        }/* w  w  w  .j  a v  a2s .  co m*/
    } else {
        count++;
    }
    return count;
}

From source file:Main.java

@NonNull
public static <T> List<T> childrenOfType(@NonNull View root, @NonNull Class<T> type) {
    final List<T> children = new ArrayList<>();
    if (type.isInstance(root)) {
        children.add(type.cast(root));//from   w ww .  jav  a 2s . c  o m
    }
    if (root instanceof ViewGroup) {
        final ViewGroup rootGroup = (ViewGroup) root;
        for (int i = 0; i < rootGroup.getChildCount(); i++) {
            final View child = rootGroup.getChildAt(i);
            children.addAll(childrenOfType(child, type));
        }
    }
    return children;
}

From source file:Main.java

@Nullable
public static <T> T firstChildOfType(@NonNull View root, @NonNull Class<T> type) {
    if (type.isInstance(root)) {
        return type.cast(root);
    }/*from w  ww  .ja v a 2s. com*/
    if (root instanceof ViewGroup) {
        final ViewGroup rootGroup = (ViewGroup) root;
        for (int i = 0; i < rootGroup.getChildCount(); i++) {
            final View child = rootGroup.getChildAt(i);
            final T childResult = firstChildOfType(child, type);
            if (childResult != null) {
                return childResult;
            }
        }
    }
    return null;
}

From source file:Main.java

public static void enableDisableViewGroup(ViewGroup viewGroup, boolean enabled) {
    int childCount = viewGroup.getChildCount();
    for (int i = 0; i < childCount; i++) {
        View view = viewGroup.getChildAt(i);
        view.setEnabled(enabled);//from   w w  w.  j av  a 2s. c om
        if (view instanceof ViewGroup) {
            enableDisableViewGroup((ViewGroup) view, enabled);
        }
    }
}

From source file:Main.java

protected static void getViewHierarchy(View v, StringBuilder accumulatedString, int indentation) {
    // append string for the passed in view
    for (int i = 0; i < indentation; ++i) {
        accumulatedString.append("|\t");
    }//ww w  .  ja v a  2s  .c o  m
    accumulatedString.append(String.format("%s : %d x %d @ (%d, %d)\n", v.getClass().toString(), v.getWidth(),
            v.getHeight(), v.getLeft(), v.getTop()));

    if (v instanceof ViewGroup) {
        ViewGroup g = (ViewGroup) v;
        ++indentation;
        for (int i = 0; i < g.getChildCount(); ++i) {
            getViewHierarchy(g.getChildAt(i), accumulatedString, indentation);
        }
    }
}

From source file:Main.java

static void getSubviewsTree(ViewGroup parentView, Class<?> classOfSubviews, ArrayList<View> result) {
    for (int i = 0; i < parentView.getChildCount(); i++) {
        View child = parentView.getChildAt(i);
        if (classOfSubviews.isAssignableFrom(child.getClass()))
            result.add(child);/*ww  w.j  a  v  a  2 s.  com*/
        if (child instanceof ViewGroup)
            getSubviewsTree((ViewGroup) child, classOfSubviews, result);
    }
}

From source file:Main.java

public static void moveToBack(View currentView) {
    ViewGroup vg = ((ViewGroup) currentView.getParent());
    int index = vg.indexOfChild(currentView);
    for (int i = 0; i < index; i++) {
        vg.bringChildToFront(vg.getChildAt(0));
    }//  w w w  .  j a  v a  2 s. c o  m
}