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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:19:04+00:00 2026-05-30T18:19:04+00:00

I have made following relative layout in an xml file lets say add_relative_layout.xml <?xml

  • 0

I have made following relative layout in an xml file lets say add_relative_layout.xml

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



</LinearLayout>

Above is the main layout in which i want to add copies of below Code file.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/UIContainer"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

<RelativeLayout

    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/white" >

    <TextView
        android:id="@+id/amountLabel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:layout_marginLeft="5dp"
        android:text="Amount"
        android:textColor="@android:color/black"
        android:textStyle="bold" />

    <EditText
        android:id="@+id/amount"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:layout_marginRight="5dp" >

    </EditText>

I have another android xml file named as Show_all.xml. It is a linear layout xml

I want to add this relative layout above as many times as i want in this show_all layout

currently i am using this code

private void callOnCreate()
      {
          linear = (LinearLayout) findViewById(R.id.addAccountLinearLayout); // the layout in which i want to make dynamic copies of this layout.
          layout = (RelativeLayout) findViewById(R.layout.ui_relative_layout_style); // name of xml File of above code.

          for (int i=0; i < 4; i++)
          {
              Account account = accountArray.get(i);
              linear.addView(layout, i);
          }   
      }

I am getting Null point exception. Please tell me what to do .

Best Regards

  • 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-30T18:19:05+00:00Added an answer on May 30, 2026 at 6:19 pm

    Hello Umar I have no idea how you can use xml layout to add Dynamically But you can use Below Code to get Your Required thing add in to LinearLayout

    public RelativeLayout createViewTOAdd(){
        lp=new RelativeLayout.LayoutParams(android.widget.RelativeLayout.LayoutParams.FILL_PARENT,android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT);
        RelativeLayout mRelativeLayout=new RelativeLayout(this);
        mRelativeLayout.setBackgroundColor(Color.WHITE);
        TextView mTextView=new TextView(this);
         RelativeLayout.LayoutParams Textview_lp=new RelativeLayout.LayoutParams(android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT,android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT);
        mTextView.setText("Amout");
        Textview_lp.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
        Textview_lp.addRule(RelativeLayout.CENTER_VERTICAL);
        Textview_lp.leftMargin=10;
        mTextView.setTextColor(Color.BLACK);
        mTextView.setTextAppearance(this, R.style.TextStyle);
        //mTextView.setLayoutParams(Textview_lp);
        EditText mEditText=new EditText(this);
         RelativeLayout.LayoutParams EditText_param=new RelativeLayout.LayoutParams(android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT,android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT);
         EditText_param.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
         EditText_param.addRule(RelativeLayout.CENTER_VERTICAL);
         EditText_param.rightMargin=10;
        //mEditText.setLayoutParams(EditText_param);
        //mRelativeLayout.addView(mTextView, 0);
        //mRelativeLayout.addView(mEditText, 1);
        //mRelativeLayout.addView(mTextView);
        //mRelativeLayout.addView(mEditText);
        mRelativeLayout.addView(mTextView, Textview_lp);
        mRelativeLayout.addView(mEditText, EditText_param);
        return mRelativeLayout;
    }
    

    Now How to add View in to LinearLayout is Below

        mLinearLayout=(LinearLayout)findViewById(R.id.mainLinearView);
    
        mLinearLayout.removeAllViews();
    
       for(int i=0;i<4;i++){
            mLinearLayout.addView(createViewTOAdd(), i);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made the following animation in my android project <?xml version=1.0 encoding=utf-8?> <set
i have made the following animation xml file in my android project: <?xml version=1.0
I have made following changes to the POM.xml file for adding a manifest file
I have created a sitecollection and in AAM I have made following settings for
I have a simple nav made up of the following HTML; <div class=inner> <div
I have an application that is made up of the following: A central database
I have roughly the following code. Could this be made nicer or more efficient?
I need to validate phone number in PHP. I have made following regex, but
I have made the following script to upload a csv and import it into
I have made the following code to render the map using tiles, it loops

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.