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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:11:53+00:00 2026-06-13T13:11:53+00:00

I have a block of Views containing an ImageView , a Button and a

  • 0

I have a block of Views containing an ImageView, a Button and a TextView. I want to create this block dynamically in the Java code. Is there a way to define this block in XML, alter the src/text attributes and append it to my current layout?

Thanks!

Ron

  • 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-13T13:11:54+00:00Added an answer on June 13, 2026 at 1:11 pm

    I use the following technique:

    <!-- content.xml -->
    <merge>
      <ImageView android:id="@+id/image />
      <Button android:id="@+id/button />
      <TextView android:id="@+id/text />
    </merge>
    

    Then inflate using a LayoutInflater:

    View block = inflater.inflate(R.layout.content, root, attach);
    (TextView) textView = (TextView) block.findViewById(R.id.text);
    textView.setText(text);
    

    I found this especially useful when you write a custom View extending a ViewGroup (eg LinearLayout or RelativeLayout) and you want to define the content in a declarative XML. For example

    public class MyWidget extends LinearLayout {
    
      // Invoked by all of the constructors
      private void setup() {
        Context ctx = getContext();
        inflate(ctx, R.layout.content, this);
        ((TextView) findViewById(R.id.text)).setText(
            ctx.getString(R.string.hello_world)
        );
      }
    }
    

    A possible variation is using a Layout instead of <merge> if you don’t need it. The LayoutInflater can be obtained by Activity.getLayoutInflater() or by any Context via getSystemService() (you have to cast the result to a LayoutInflater object in the latter case.

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

Sidebar

Related Questions

I have a block of code in my view like this: <% @map[value].each do
I have a block of HTML code that contains a button <button class=someButton onclick=openPage('test')></button>
I have a block of code in C like this- enum colors { //---->I
I have this block of code inside a loop: var points = [new google.maps.LatLng(lat1,
I want to have a dialog containing 3 views 1. title with black background
i have build an About the Author views block in Drupal. This is linked
I have a UITableView. On the tap of a button i want to display
I'm working on drupal 7 website. I have a VIEWS Block List for a
I have a list of client logos (Views Block) at frontpage. Images are generated
I have isolated the problem in the second block of code below (if you

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.