Skip to content Skip to sidebar Skip to footer

Get Id's Of All The Buttons Within Parent Layout

I'm developing an Android app in java with eclipse. I have 2 Relative layouts within my XML. One layout has 2 buttons within it and the other has 3 buttons. I'm trying to some how

Solution 1:

Loop through parent view to get all child views

ViewGroup parentView = (ViewGroup) findViewById(R.id.linearLayout1);
for(int i=0; i < parentView.getChildCount(); i++) {
    View childView = parentView.getChildAt(i);
    int resID = childView.getId();
}

Post a Comment for "Get Id's Of All The Buttons Within Parent Layout"