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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:57:31+00:00 2026-06-01T05:57:31+00:00

In my Android Activity, I need to add a single View dynamically (at runtime),

  • 0

In my Android Activity, I need to add a single View dynamically (at runtime), at a specific position in a layout. The view to be added is determined at runtime. For example, may layout may look something like this:

<LinearLayout ...>
    <TextView ... />
    <!-- Dynamic item to be added here -->
    <TextView ... />
</LinearLayout>

What is the best way to achieve this?

One solution is to use layout.addView(view, index), but I’d prefer not to hardcode the index.

Another solution is to use a FrameLayout as a placeholder, and place may dynamic view inside the FrameLayout, for example:

<LinearLayout ...>
    <TextView ... />
    <FrameLayout android:id="@+id/placeholder" />
    <TextView ... />
</LinearLayout>

Then:

findViewById(R.id.placeholder).addView(view);

However, this adds an unnecessary view in the hierarchy.

What would be the recommended way to do this?

  • 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-01T05:57:32+00:00Added an answer on June 1, 2026 at 5:57 am

    I think that using a FrameLayout as a placeholder for your view “added at runtime” is a good solution.

    I would not worry about the impact of the extra “unnecesssary” view on performance.

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

Sidebar

Related Questions

In an Android application I need to add a view to my RelativeLayout that
I'm trying to add a support.v4.app.Fragment to a PreferenceActivity header, like so: <header android:fragment=com.example.SupportFragmentSubClass
I need to add two text view to the list view as shown in
i need to add an help window to my android application. But actually i
I need to add a number of rows to my Table layout and to
I'm working on an Android project and I need to add buttons to a
In an given Android activity, I would like to start a new activity for
So I have a very simple android activity that starts a timer when you
I would like to implement the following simple pattern in an android app: Activity
Here is my code import org.ksoap2.*; import org.ksoap2.serialization.*; import org.ksoap2.transport.*; import android.app.Activity; import android.os.Bundle;

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.