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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:29:28+00:00 2026-06-04T17:29:28+00:00

I have designed a layout as in the image below: After entering text in

  • 0

I have designed a layout as in the image below:

image

After entering text in the EditText, when I press the Add+ Button the TextView and Button will be added as shown in the image below:

image

I want to show the Button on the right side of the TextView. How should I do this?
Another question, how should I remove corresponding View when user clicks a button? The code:

 public class ExampleActivity extends Activity {
    private LinearLayout mLayout;
    private EditText mEditText;
    private Button mButton;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        mLayout = (LinearLayout) findViewById(R.id.linearLayout);
        mEditText = (EditText) findViewById(R.id.editText);
        mButton = (Button) findViewById(R.id.button);
        mButton.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                mLayout.addView(createNewTextView(mEditText.getText()
                        .toString()));
                mLayout.addView(createNewButton());
            }
        });

    }

    private TextView createNewTextView(String text) {
        final LayoutParams lparams = new LayoutParams(
                LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        final TextView textView = new TextView(this);
        textView.setLayoutParams(lparams);
        textView.setText("New text: " + text);
        return textView;
    }

    private Button createNewButton() {
        final LayoutParams lparams = new LayoutParams(
                LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        final Button button = new Button(this);
        button.setLayoutParams(lparams);
        button.setText(" - ");
        return button;
    }
  }
  • 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-04T17:29:29+00:00Added an answer on June 4, 2026 at 5:29 pm

    The TextViews and Buttons are stacked because you probably use a LinearLayout with the orientation vertical. You could wrap your TextView + Button into a LinearLayout and then add this LinearLayout to your own layout or you could use a TableLayout like below(I’ve added some ids so you can delete the rows you want):

    public class SomeActivity extends Activity {
    
        private EditText mInput;
            private TableLayout mTable;
            private static int sCount = 0;
    
            @Override
            protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.main);
                Button addButton = (Button) findViewById(R.id.add);
                mInput = (EditText) findViewById(R.id.editText1);
                mTable = (TableLayout) findViewById(R.id.table1);
                addButton.setOnClickListener(new OnClickListener() {
    
                    @Override
                    public void onClick(View v) {
                        mTable.addView(addRow(mInput.getText().toString()));
                    }
                });
            }
    
            private TableRow addRow(String s) {
                TableRow tr = new TableRow(this);
                tr.setId(1000 + sCount);
                tr.setLayoutParams(new TableLayout.LayoutParams(
                        TableLayout.LayoutParams.FILL_PARENT,
                        TableLayout.LayoutParams.WRAP_CONTENT));
                TableRow.LayoutParams tlparams = new TableRow.LayoutParams(
                        TableRow.LayoutParams.WRAP_CONTENT,
                        TableRow.LayoutParams.WRAP_CONTENT);
                TextView textView = new TextView(this);
                textView.setLayoutParams(tlparams);
                textView.setText("New text: " + s);
                tr.addView(textView);
                TableRow.LayoutParams blparams = new TableRow.LayoutParams(
                        TableRow.LayoutParams.WRAP_CONTENT,
                        TableRow.LayoutParams.WRAP_CONTENT);
                final Button button = new Button(this);
                button.setLayoutParams(blparams);
                button.setText(" - ");
                button.setId(2000 + sCount);
                button.setOnClickListener(new OnClickListener(){
    
                    @Override
                    public void onClick(View v) {               
                        mTable.removeView(findViewById(v.getId() - 1000));
                    }           
                });
                tr.addView(button);
                sCount++;
                return tr;
        }
    
    }
    

    where the main layout file is:

    <?xml version="1.0" encoding="utf-8"?>
    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
    
        <LinearLayout
            android:id="@+id/parent"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >
    
            <EditText
                android:id="@+id/editText1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
    
            <Button
                android:id="@+id/add"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
    
            <TableLayout
                android:id="@+id/table1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" >
            </TableLayout>
        </LinearLayout>
    
    </ScrollView>
    

    If for some reason, you don’t like the TableLayout use a LinearLayout to wrap you TextView and Button with the layout file above(and of course remove the TableLayout):

    //...
    ll = (LinearLayout) findViewById(R.id.parent);
            addButton.setOnClickListener(new OnClickListener() {
    
                @Override
                public void onClick(View v) {
                    //where ll is the LinearLayout with the id parent
                    ll.addView(addRow(mInput.getText().toString()));
                }
            });
        }
    
        private LinearLayout addRow(String s) {
            LinearLayout tr = new LinearLayout(this);
            tr.setId(1000 + sCount);
            tr.setLayoutParams(new LinearLayout.LayoutParams(
                    LinearLayout.LayoutParams.FILL_PARENT,
                    LinearLayout.LayoutParams.WRAP_CONTENT));
            LinearLayout.LayoutParams tlparams = new LinearLayout.LayoutParams(
                    LinearLayout.LayoutParams.WRAP_CONTENT,
                    LinearLayout.LayoutParams.WRAP_CONTENT);
            TextView textView = new TextView(this);
            textView.setLayoutParams(tlparams);
            textView.setText("New text: " + s);
            tr.addView(textView);
            LinearLayout.LayoutParams blparams = new LinearLayout.LayoutParams(
                    LinearLayout.LayoutParams.WRAP_CONTENT,
                    LinearLayout.LayoutParams.WRAP_CONTENT);
            final Button button = new Button(this);
            button.setLayoutParams(blparams);
            button.setText(" - ");
            button.setId(2000 + sCount);
            button.setOnClickListener(new OnClickListener(){
    
                @Override
                public void onClick(View v) {               
                    ll.removeView(findViewById(v.getId() - 1000));
                }           
            });
            tr.addView(button);
            sCount++;
            return tr;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have designed an XML layout as in this image: I need to equally
I have a doubt in layouts.I have designed one layout using group layout using
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
I have designed one sign-up form,in this form after getting all necessary values I
I have designed a database whose MDF file will be copied to remote offices,
I have a web layout originally designed for use with televisions (running from a
Can I embed Tab Layout into other layout? The designed layout is like below:
I have developed application in Android and designed one splash screen image of size
I have designed my layout and on smaller phone screens not everything is visible,
I have designed a layout and i find some gaps in the stacking of

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.