I am making a Custom Layout Android component by extending abstract class ViewGroup (as per this video tutorial by Romain Guy on Parleys.com : http://www.parleys.com/#st=5&id=2191&sl=1).
My component should contain children, but I want to restrain that to only 1 child, of type ViewGroup as well (such as another LinearLayout or a RelativeLayout). Kindof like the ScrollView. Is there a way to add that restriction?
EDIT: Final solution as android developer said, is to programatically check the constraints onFinishInflate of the ViewGroup subclass as such:
@Override
public void onFinishInflate()
{
if (getChildCount() > 1)
throw new IllegalArgumentException("Only 1 child allowed");
if (getChildCount() == 0 || !(getChildAt(0) instanceof ViewGroup))
throw new IllegalArgumentException("Child must be a ViewGroup");
}