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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:31:46+00:00 2026-06-14T18:31:46+00:00

I have a xml layout with a RelativeLayout that holds 4-5 subviews. I want

  • 0

I have a xml layout with a RelativeLayout that holds 4-5 subviews. I want to have a custom View class based on this xml layout with a custom onclick listner.

I have tried with a custom class by extending RelativeLayout and by having a View as member. And in my constructor i’m inflating the layout and assigning it to my View member. But I want to have the class itself similar to my inflated view object.
(did I make any sense!!)

my current code is similar to below:

public class CustomItemView extends RelativeLayout {
  private Context context;
  private View itemView;

  public CustomItemView(Context context) {
    super(context);
    this.context = context;

     LayoutInflater inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

      itemView = inflater.inflate(layout, null);                
  }

  public View getView() {
    return itemView;
  }       
}
  • 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-14T18:31:47+00:00Added an answer on June 14, 2026 at 6:31 pm

    One simple way to achieve it is to extend FrameLayout and attach the inflated layout to oneself (this) in the constructor:

    public class MyView extends FrameLayout {
    
        public MyView(Context context, AttributeSet attrs) {
            super(context, attrs);
            LayoutInflater.from(context).inflate(R.layout.my_view, this);
        }
    
        // Your view logic here
    }
    

    Then you can use your brand new view programatically:

    MyView myView = new MyView(context);
    

    Or in an XML layout:

    <packageName.MyView
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In My Application, My XML layout is like this: <RelativeLayout android:layout_width=fill_parent android:layout_height=fill_parent> <View class=com.project.twsbi.FingerPaint$MyView
I have designed the screen using this relative layout. <?xml version=1.0 encoding=utf-8?> <RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android
So, I have this layout: <?xml version=1.0 encoding=utf-8?> <RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android android:id=@+id/layout android:layout_width=fill_parent android:layout_height=wrap_content android:background=#FFFF00
I have an XML layout and want to add my own custom SurfaceView to
So I have a custom view set up in code (no XML layout defined
I have a custom listView. The main layout xml is something like this: <?xml
I have a RelativeLayout that looks like this: <?xml version=1.0 encoding=utf-8?> <RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android android:layout_width=fill_parent
In an XML layout that is a RelativeLayout I have a nested LinearLayout. Within
I have a simple screen created in xml, the parent layout is a relativelayout
I have a layout defined in XML. It contains also: <RelativeLayout android:id=@+id/item android:layout_width=fill_parent android:layout_height=wrap_content

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.