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

The Archive Base Latest Questions

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

I want to add a LinearLayout wrapped around a TextView and Button programmatically. I

  • 0

I want to add a LinearLayout wrapped around a TextView and Button programmatically. I want it to take a String array and then using the length of the string array, add that many TextViews each with their own button.

So first:

String [] s = { .... the values ....}
int sL = s.length;
TextView t1 = new TextView (this);
// then somehow create t2, t3... etc. matching the length of the String array.

Is this the best way to do this or is there another way to do this? For some context, it’s a quiz app and I’ve created a list of categories inside resources as values and I’m trying to programmatically get my app to create as many TextViews as there are categories then set each TextView to each category then get each button to take the user to that category of questions.

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

    You are starting it right, just do a for loop and add textviews to your linearlayout.

    // You linearlayout in which you want your textview
    LinearLayout linearLayout = (LinearLayout) findViewById(R.id.mylayout);
    linearLayout.setBackgroundColor(Color.TRANSPARENT);
    
    String [] s = { .... the values ....}
    int sL = s.length;
    TextView textView = null;
    
    // For later use if you'd like
    ArrayList<TextView> tViews = new ArrayList<TextView>();
    
    for (int i = 0; i < sL; i++)
    {
        textView = new TextView(this);
        textView.setText(s[i]);
        linearLayout.addView(textView);
        tViews.add(textView);
    }
    

    There is nothing wrong with this way of doing it. If you want to use these textview later on (set text for them or something) store them in an Array of some kind. Edited code

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

Sidebar

Related Questions

I have a problem that, I want to add a textView or a button
I want to add linearlayout in table row and that linear layout will hold
I have a list of string values that I want add to a hashtable
I using the 'LinearLayout' and i add 4 controls. 1. textView_1 - that contain
I have a LinearLayout that I am extending and I want to add a
I would like to add programmatically to LinearLayout some TextViews . And I want
I have a LinearLayout view that already contains several elements. I want to add
I want to add a Relative Layout below a TextView and above a Button.
I want to programmatically add Text Views controls to my home screen widget. In
My app plays a video using VideoView. I am using a LinearLayout to add

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.