Example usage for android.view ViewGroup getChildCount

List of usage examples for android.view ViewGroup getChildCount

Introduction

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

Prototype

public int getChildCount() 

Source Link

Document

Returns the number of children in the group.

Usage

From source file:com.nkahoang.screenstandby.BaseActivity.java

protected static void SetMetroFont(ViewGroup layout) {
    for (int i = 0; i < layout.getChildCount(); i++) {
        TextView text = (layout.getChildAt(i) instanceof TextView ? (TextView) layout.getChildAt(i) : null);
        if (text != null)
            text.setTypeface(typeface);//from  ww w. ja va2 s.  co  m
    }
}

From source file:Main.java

protected static void makeMultiline(View view) {
    if (view instanceof ViewGroup) {

        ViewGroup grp = (ViewGroup) view;

        for (int index = 0; index < grp.getChildCount(); index++) {
            makeMultiline(grp.getChildAt(index));
        }/* ww w .j  a  v a2  s  .  co m*/
    } else if (view instanceof TextView) {
        TextView t = (TextView) view;
        t.setSingleLine(false);
        t.setEllipsize(null);
    }
}

From source file:Main.java

public static View findViewByClassName(ViewGroup v, String viewClassName) {
    View a;//from   ww w  .j  ava 2  s  .c om
    for (int i = 0; i < v.getChildCount(); i++) {
        a = v.getChildAt(i);
        if (a.getClass().getName().equals(viewClassName))
            return a;

        if (ViewGroup.class.isAssignableFrom(a.getClass())) {
            View b = findViewByClassName((ViewGroup) a, viewClassName);
            if (b != null)
                return b;
        }
    }
    return null;
}

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));/*ww w. ja  v a  2 s  .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

public static void setFontAllView(ViewGroup vg) {
    for (int i = 0; i < vg.getChildCount(); ++i) {
        View child = vg.getChildAt(i);

        if (child instanceof ViewGroup) {
            setFontAllView((ViewGroup) child);
        } else if (child != null) {
            Typeface face;/*from  ww  w. ja  v  a  2  s .  com*/
            if (child.getTag() != null && child.getTag().toString().toLowerCase().equals("bold")) {
                face = boldFont;
            } else {
                face = regularFont;
            }

            if (child instanceof TextView) {
                TextView textView = (TextView) child;
                textView.setTypeface(face);
            } else if (child instanceof EditText) {
                EditText editView = (EditText) child;
                editView.setTypeface(face);
            } else if (child instanceof RadioButton) {
                RadioButton radioView = (RadioButton) child;
                radioView.setTypeface(face);
            } else if (child instanceof CheckBox) {
                CheckBox checkboxView = (CheckBox) child;
                checkboxView.setTypeface(face);
            } else if (child instanceof Button) {
                Button button = (Button) child;
                button.setTypeface(face);
            }
        }
    }
}

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);
    }// ww w . j ava2s  . 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);
            final T childResult = firstChildOfType(child, type);
            if (childResult != null) {
                return childResult;
            }
        }
    }
    return null;
}

From source file:Main.java

public static void setupTypeface(View view, Typeface globalFace) {
    try {//from   w  w  w  .  j av  a 2 s. com
        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 void unwrapView(ViewGroup wrapper) {
    final int childCount = wrapper.getChildCount();
    View[] childViews = new View[childCount];

    ViewGroup parent = (ViewGroup) wrapper.getParent();

    if (parent != null) {
        parent.removeView(wrapper);//  ww  w.j  a  v a2  s. co m
    }

    for (int i = 0; i < childCount; i++) {
        childViews[i] = wrapper.getChildAt(i);
    }

    // If there was just one wrapper reuse the wrapper layout
    // params to ensure correct type for parent
    if (childCount == 1) {
        ViewGroup.LayoutParams wrapperParams = wrapper.getLayoutParams();
        if (wrapperParams != null) {
            childViews[0].setLayoutParams(wrapperParams);
        }
    }

    for (int i = 0; i < childCount; i++) {
        final View childView = childViews[i];

        wrapper.removeView(childView);
        if (parent != null) {
            parent.addView(childView);
        }
    }
}

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  ava2  s. co m
        if (child instanceof ViewGroup)
            getSubviewsTree((ViewGroup) child, classOfSubviews, result);
    }
}

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");
    }//from w ww.j av a 2  s .  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);
        }
    }
}