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 6243233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:06:06+00:00 2026-05-24T12:06:06+00:00

I’m trying to extend a LinearLayout to use as a composite component. I have

  • 0

I’m trying to extend a LinearLayout to use as a composite component. I have followed this tutorial:
link

Which seems fairly straight forward. However when I try to inflate my component it fails all the time. The error I get from logCat is that my class can’t be found. It seems strange to me that as far as I can see android searches for my component among it’s own components (I’m unsure about the correct wording here, please se below).

The code I have written is as follows:

main (the current activity):

//just the ordinary autogenerated eclipse code...
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
}

My extended linear layout:

public class DialPadView extends LinearLayout {

public DialPadView(Context ctx, AttributeSet attr) {
    super(ctx, attr);
}


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

}

My main.xml layout file

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<whalenut.testinflate.DialPadView
    android:id="@+id/mydialpad"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    /></LinearLayout>

and finally my dialpadview.xml file to use with my composite component:

<?xml version="1.0" encoding="utf-8"?>
<DialPadView
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:orientation="vertical"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent">
   <EditText 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="test"/>
</DialPadView>

ofcourse all my class files resides in the package whalenut.testinflate

logCat says this:

java.lang.RuntimeException: Unable to start activity ComponentInfo{whalenut.testinflate/whalenut.testinflate.TestInflateActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class DialPadView

…

Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class DialPadView

…

Caused by: java.lang.ClassNotFoundException: android.view.DialPadView in loader dalvik.system.PathClassLoader[/data/app/whalenut.testinflate-2.apk]

Why is Dalvik(?) searching for my class in the package android.view instead of whalenut.testinflate when I have given the fully qualified classname in the xml-file, is it because it doesn’t find it there to begin with?

In short why can’t I, or rather how do I inflate a extended Layout in android?

  • 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-24T12:06:07+00:00Added an answer on May 24, 2026 at 12:06 pm

    You need to change your DialPadView as follows:

    <merge android:class="com.packageName.UIClassName"
        android:id="@+id/DialView"
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
    <EditText android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="test"/>
    </merge>
    

    Then call this in your constructor:

    super(context, attrs, defStyle);
    
    LayoutInflater inflater = (LayoutInflater) context
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    
    inflater.inflate(R.layout.DialView, this, true);
    

    You can then use the following in your main activity:

    DialView myDialView = new DialView(context);
    
    mainView.addView(myDialView);
    

    I hope this helps!

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I am trying to loop through a bunch of documents I have to put
I have some data like this: 1 2 3 4 5 9 2 6

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.