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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:34:29+00:00 2026-06-07T23:34:29+00:00

I have layout file which I’m inflating dynamically on the screen. Then in my

  • 0

I have layout file which I’m inflating dynamically on the screen.
Then in my activity I have to init some UI logic (listeners, etc…).

But now this logic needs to be moved to some class. And I can’t decide what way is the best to create view based object that has its layout in xml.

public MyView extends View {
    MyView(Context context) {
        super(context);
        //inflation here...        
    }

OR

MyViewFactory {
    View get(Inflater inflater) {

    }

OR something else?

May be someone can also recommend source code where to look for.

  • 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-07T23:34:32+00:00Added an answer on June 7, 2026 at 11:34 pm

    You probably don’t want to do this with a simple view like ImageView. you want it to be a more complex layout like (linear layout containing buttons etc)?

    In case you need the first you are best off with a simple view instance like ImageView img = new ImageView(context); or a factory if you have more parameters involved if you think its simpler setting them in xml.

    As far as more complex layouts go i prefer using a custom class extending some of the viewGroups(Like: MyView extends LinearLayout)

    create a function called init();

    call the function from each constructor

    implement inside it something like:

    LayoutInflater.from(context).inflate(R.layout.my_layout,this,true);
    

    this + true would mean that the layout will be attached to the root, in this case linearLayout and you can use findViewById directly on the viewgroup)

    ImageView img = findViewById(R.id.myView);
    

    i find it really important to create custom views since they always include logic that is specific to them and can be reused and also expose some public methods to invoke from the activities that include the custom view.

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

Sidebar

Related Questions

I have a simple layout file which displays the icons and some text view
I have some layout file which Lint is giving me the following warning about:
I have <.ImageView> enter code here s(icons) in my android layout xml file, which
I have an xml layout file which contains a few widgets including a Spinner
I have a layout xml file named my_layout.xml, in which the root view's layout_width
I have a RelativeLayout defined in an xml layout file named 'myview.xml' which contains
I have an application.html.erb file which sets out layout for every pages in my
I have an activity with a listView, which uses a custom row layout defined
it's just a simple question: I have a layout file which is presented as
I have a JSON file which is populated to an activity (Main.java). This Activity

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.