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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:14:01+00:00 2026-06-05T03:14:01+00:00

Hello I want to click a button that will add a new button to

  • 0

Hello I want to click a button that will add a new button to a table row every time it is clicked. After 3 buttons have been added to the row, I want to dynamically create a new table row and add a new button to it.

I know how to add a row with a button(s) to a tableLayout if I click a button. I don’t know how to modify the table row every time I click so I can add an additional button.

Any advice would be quite helpful and appreciated.

Following is my code but this is not perfect

public class DynamicTableView extends Activity {

    TableLayout mTlayout;
    String[] mTextofButton = { "Dipak", "E", "I", "J", "L",
            "M", "G", "R", "N", "T", "H", "P",
            "K", "Y", "V" };

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        mTlayout = (TableLayout) findViewById(R.id.mTlayout);


        TableRow tr=new TableRow(this);
        for(int i=0;i<mTextofButton.length;i++){
            Button btn=new Button(this);
            btn.setText(mTextofButton[i]);
            tr.addView(btn);

        }   
        mTlayout.addView(tr);
    }
}

Thanks in advance.

  • 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-05T03:14:03+00:00Added an answer on June 5, 2026 at 3:14 am

    Use following Code:-

    public class DynamicButtonsActivity extends Activity {
    
        TableLayout mTlayout;
        TableRow tr;
        String[] mTextofButton = { "D", "E", "I", "J", "L", "M", "G", "R", "N",
                "T", "H", "P", "K", "Y", "V" };
    
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            mTlayout = (TableLayout) findViewById(R.id.mTlayout);
    
            int i = 0;
            while (i < mTextofButton.length) {
                if (i % 3 == 0) {
                    tr = new TableRow(this);
                    mTlayout.addView(tr);
                }
                Button btn = new Button(this);
                btn.setText(mTextofButton[i]);
                btn.setId(i);
                btn.setOnClickListener(new OnClickListener() {
    
                    @Override
                    public void onClick(View v) {
                        // TODO Auto-generated method stub
                        System.out.println("v.getid is:- " + v.getId());
                    }
                });
                tr.addView(btn);
                i++;
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want after click on button append value hello 2 in tag td with
Hello friends i want to add more effects on my div when i click
Hello I want to add a new subitem in a listView listView.Items[0].SubItems.Add(textBox.Text); I clip
I want to render a view when user clicks on Add New button on
Hello guys I have 1675 line Code. Want to when user click button textbox.text
I want to add views on click of button. My screen has a text
Hello i want to replace the text in div when user click on it
Hello I want to know how to highlight all Words that is inputted in
Hello friends I want when user checked the radio box then the text will
Hello Friends I want to upload a image but according to requirement when click

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.