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 makeChildrenInvisible(ViewGroup view) {
    for (int i = 0; i < view.getChildCount(); i++) {
        view.getChildAt(i).setVisibility(View.GONE);
    }// w w  w.  j a v a  2s .co m
}

From source file:Main.java

public static View findLastChildView(ViewGroup group) {
    if (group != null && group.getChildCount() > 0)
        return group.getChildAt(group.getChildCount() - 1);
    return null;/*  w  w w .  j a v  a2 s .c o  m*/
}

From source file:Main.java

public static void removeView(Activity act, View v) {
    ViewGroup root = (ViewGroup) act.findViewById(android.R.id.content);
    root = (ViewGroup) root.getChildAt(0);
    root.removeView(v);/*from w ww .j  av a  2 s  .  co m*/
}

From source file:Main.java

/**
 * getContentView from an activity//from  ww w.ja  va2  s . c o  m
 * @param activity
 * @return View
 */
public static View getContentView(Activity activity) {
    ViewGroup view = (ViewGroup) activity.getWindow().getDecorView();
    ViewGroup content = (ViewGroup) view.findViewById(android.R.id.content);
    return content.getChildAt(0);
}

From source file:Main.java

public static void addViewToRoot(Activity act, View v) {
    ViewGroup root = (FrameLayout) act.findViewById(android.R.id.content);
    root = (ViewGroup) root.getChildAt(0);
    ViewGroup.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    root.addView(v, params);/*from w w  w.  j  a  v  a  2s .co m*/
}

From source file:Main.java

public static void stateControls(boolean able, ViewGroup vg) {
    for (int i = 0; i < vg.getChildCount(); i++) {
        View child = vg.getChildAt(i);
        child.setEnabled(able);/* w  w  w  .  j  a  v  a  2  s.  c  om*/
        if (child instanceof ViewGroup) {
            stateControls(able, (ViewGroup) child);
        }
    }
}

From source file:Main.java

public static void setChildrenAlpha(ViewGroup parent, float alpha) {
    for (int i = parent.getChildCount() - 1; i >= 0; --i) {
        parent.getChildAt(i).setAlpha(alpha);
    }/*from w w  w. ja  va  2s . c o  m*/
}

From source file:Main.java

public static boolean IsFormCompleted(ViewGroup v) {
    for (int i = 0; i < v.getChildCount(); i++) {
        Object child = v.getChildAt(i);

        if (child instanceof EditText) {
            EditText e = (EditText) child;

            if (e.getText().length() == 0)
                return false;
        } else if (child instanceof RadioGroup) {
            RadioGroup rb = (RadioGroup) child;

            if (rb.getCheckedRadioButtonId() < 0)
                return false;
        }/*w  w  w. j av  a2s.co  m*/
    }

    return true;
}

From source file:Main.java

/**
 *
 * @param act//  www .j  a v  a  2s.  c o m
 * @return
 */
public static RelativeLayout getContainerView(Activity act) {
    // create a new relative layout
    RelativeLayout rl = new RelativeLayout(act);

    // fint the root view of the activity
    ViewGroup fl = (ViewGroup) act.findViewById(android.R.id.content);
    fl = (ViewGroup) fl.getChildAt(0);
    Log.d("DEBUG", "w: " + fl.getWidth() + "h: " + fl.getHeight());

    // Params
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(-1, -1);
    //        new FrameLayout.LayoutParams(-1, -1);
    // add to the root view of the activity
    fl.addView(rl, params);

    return rl;
}

From source file:Main.java

/**
 * Searches a {@link ViewGroup} for the first {@link ImageView} it can find in its child views.
 *
 * @param container The container {@link ViewGroup}.
 * @return The first {@link ImageView} in the {@code container ViewGroup} (counted by child
 * indexes), or {@code null} if no {@code ImageView} was found.
 *//*w  w  w  .  j  av a 2  s  .  co  m*/
public static ImageView findFirstImageView(ViewGroup container) {
    for (int i = 0; i < container.getChildCount(); i++) {
        View v = container.getChildAt(i);
        if (v instanceof ImageView) {
            return (ImageView) v;
        } else if (v instanceof ViewGroup) {
            return findFirstImageView((ViewGroup) v);
        }
    }
    return null;
}