Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8367489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:10:19+00:00 2026-06-09T13:10:19+00:00

I am making a Custom Layout Android component by extending abstract class ViewGroup (as

  • 0

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");
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T13:10:21+00:00Added an answer on June 9, 2026 at 1:10 pm

    sure you can .

    simply get the child count by using getChildCount() in order to check that there is only a single child.

    then, get the only child there is in the viewGroup by using getChildAt(0) .

    after this , use reflection on the result and do whatever extra checks you wish to do on its class (for example , use getSuperclass()

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a custom component that shows a little drop down area after you
I'm making a custom XML layout to display a cocktail recipe. Here is my
I am making a custom titlebar using the following xml file: <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android android:id=@+id/myTitle
This is a question on making custom fields in Django. I'm making a field
When autoloading libraries, helpers or models, does this also hold true when making custom
I'm making a simple custom dialog for my android app, displaying only a seek
Is anyone aware of a custom layout component that can take css to position
I have the following code based on this great template for making custom WordPress
I have currently implemented a custom ViewGroup class, that attempts to position items (buttons
I making a custom button, and I need to add a PreviewKeyDown event, whenever

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.