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

  • Home
  • SEARCH
  • 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 5970849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:26:02+00:00 2026-05-22T20:26:02+00:00

Greets. I’m working on a project and thought I would roll up a composite

  • 0

Greets. I’m working on a project and thought I would roll up a composite component. I laid them out in xml and wrote up a new class that extends LinearLayout. Basically, I will need about five or six of them in an Activity. I want to create these inside of an Activity programmatically because I don’t know how many I will need before runtime. Also, I created an xml file to set them up which I haven’t included below. I am having a problem with each of the methods I have found to do this.

Here are the method segments inside of the class I made that extends LinearLayout:

public ExtendedLinearLayout(Context context, AttributeSet attrs) {
    super(context, attrs);
    ...
}

@Override
protected void onFinishInflate() {
    super.onFinishInflate();
    ((Activity)getContext()).getLayoutInflater().inflate(R.layout.extended_linear_layout, this);
    ...
}

And inside the Activity, these are the two solutions that appear to be the closest to what I’m looking for.

Don’t know where to get the attrs from using this method:

ExtendedLinearLayout customViewClass = new ExtendedLinearLayout(this, attrs);
layout.addView(customViewClass)

Dont know how to specify that the inflater should use the ExtendedLinearLayout with this method:

LayoutInflater inflater = LayoutInflater.from(this);
inflater.inflate(R.layout.extended_linear_layout, parent_layout);

I will probably settle for using a ListView – but it seems a bit overkill for five to six items. Also, having worked with Flex before, this at least seems like a reasonable solution to the problem.

Thanks,
Randall

—————-UPDATE——————-

I’ve tried the method as discussed below. Once I set everything up I’m getting an InflationException: Binary XML file line #8: Error inflating class. I feel like the xml looks just fine. One thing I may be confused about is where to call the inflater. Right now, I’m calling the inflater in onFinishInflate() of the custom class as well as in the Activity as follows:

public class ExtendedLinearLayout extends LinearLayout {
    ...
public ExtendedLinearLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        inflater.inflate(R.layout.extended_linear_layout, null);
        ...
    }
}

And in the activity:

public class TestActivity extends Activity {
    LinearLayout list;
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        list = (LinearLayout) findViewById(R.id.simple_list);
        runTestCode();
    }
    private void runTestCode() {
        LayoutInflater inflater = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        ExtendedLinearLayout layoutOne = 
                (ExtendedLinearLayout) inflater.inflate(R.layout.extended_linear_layout, list);
    }
}

Thanks and hope you’ve got time to take a look. I like to figure out stuff by digging around online but this one has had me cooked for a number of hours since yesterday morning. I’m about 2 inches away from just refactoring this into a ListAdapter.

—————-UPDATE——————-

Here is the xml file

<?xml version="1.0" encoding="utf-8"?>
<com.anotherandroidblog.ExtendedLinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal"
    >
    <TextView
        android:id="@+id/text_one"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text=""
        ></TextView>
    <TextView
        android:id="@+id/text_two"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text=""
        ></TextView>
    <TextView
        android:id="@+id/text_three"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="2"
        ></TextView>
</com.anotherandroidblog.ExtendedLinearLayout>
  • 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-05-22T20:26:02+00:00Added an answer on May 22, 2026 at 8:26 pm

    You need to use the full class name in the XML file: instead of making the root element LinearLayout make it the full class name for ExtendedLinearLayout (including package name). Then the LayoutInflater will know what to do.

    EDIT: also, the attrs option isn’t really workable (or at least I don’t think so). I haven’t found a way to generate at runtime the actually attrs object instance: there are no public constructors and I expect that’s another one of the things the framework does under the hood that’s just not accessible.

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

Sidebar

Related Questions

Greets, When working with DirectX, you get this nice header to #include called DxErr9.h
Greets. So, I'm running Fedora Core 8 on an Amazon EC2. I installed httpd,
Greets. I realize this might be seen as a duplicate question as this but
Greets, Does anyone how I go about detecting when a user presses on a
Greets- We gots a few nutters in work who enjoy using while(true) { //Code
Greets, Made some app on android. I for the life of me can't get
Greets! I'm a noob struggling to learn html and javascript - getting there slowly.
Greets. A somehow detailed explanation on my problem, and what I have already done,
Possible Duplicate: C# generic constraint for only integers Greets! I'm attempting to set up
Strange question, but: Sharepoint 2007 greets you with the Administrator Tasks on the Central

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.