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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:16:49+00:00 2026-05-30T19:16:49+00:00

I’m having an issue with my android application. I want to dynamically create 4

  • 0

I’m having an issue with my android application. I want to dynamically create 4 TableRows in a TableLayout. Each of this row will contain 1 TextView. I want the TextView like this:

 textview1
 textview2
 textview3
 textview4

in 4 different rows.

I am able to create the Tewtview dynamically but the sizes are not matching. For example if my first textview contains a big text, it appears to be in single text without being continued to the next line

I read a lot of similar questions but couldn’t find the solution. Here is my layout file:

<Relativelayout>

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_marginTop="10dip" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_below="@+id/didyoudo"
android:layout_above="@+id/bardown" android:scrollbarFadeDuration="1000"
android:scrollbarSize="12dip">

<TableLayout android:id="@+id/answertable"
    android:layout_width="fill_parent" android:layout_height="wrap_content"
    android:stretchColumns="0,1" android:collapseColumns="2">


  </TableLayout>
</ScrollView>
<Relativelayout/>

And this is how I’m generating the rows and textview dynamically

for (k =0; k< questionCount;k++ ) {
                    //tmpDict = trivialist.get(k);
                    Trivia trivia = trivialist.get(k);
                    TableRow row = new TableRow(getApplicationContext());
                    TableRow row1 = new TableRow(getApplicationContext());
                    TableRow row2 = new TableRow(getApplicationContext());
                    TableRow row3 = new TableRow(getApplicationContext());
                    TextView tv1 = new TextView(getApplicationContext());
                    TextView tv2 = new TextView(getApplicationContext());
                    TextView tv3 = new TextView(getApplicationContext());
                    TextView tv4 = new TextView(getApplicationContext());
                     desc = trivia.getAnswerDesc();
                     quizquestion = trivia.getStrQuestion();
                    tv1.setText("\n\t" + quizquestion);
                    tv1.setTextColor(Color.WHITE); 
                    tv1.setSingleLine(false);
                    tv1.setLines(2);
                    tv1.setHorizontallyScrolling(false);
                    tv1.setTextSize(15);
                    tv1.setTypeface(null, Typeface.BOLD);

                            try {
                                //if the below value is null, it means that the selected answer is wrong 
                                // and enters to the else block
                                if (triviaDict.get("correctAnswer") != null) {
                                    String answer = (String) triviaDict.get("correctAnswer");
                                    tv2.setText("\n\t" + "You said: "+ answer + "\n");
                                    tv2.setTextColor(Color.WHITE);
                                    tv2.setSingleLine(false);
                                    tv2.setHorizontallyScrolling(false);
                                    tv2.setTextSize(15);
                                    tv2.setLines(2);
                                    tv2.setTypeface(null, Typeface.BOLD);

                                    tv3.setText("\t" +"That's Right."+ desc+"\n");
                                    tv3.setTextColor(Color.WHITE);
                                    tv3.setSingleLine(false);
                                    tv3.setHorizontallyScrolling(false);
                                    tv3.setTextSize(15);
                                    tv3.setLines(2);
                                    tv3.setTypeface(null, Typeface.BOLD);

                                    tv4.setText("\t" + "_____________________________________" );
                                    tv4.setTextColor(Color.WHITE);
                                    tv3.setHorizontallyScrolling(false);
                                    tv4.setTypeface(null, Typeface.BOLD);
                                } else {
                                    String wronganswer = (String) triviaDict.get("selected");
                                    tv2.setText("\n\t" + "You said:"+ wronganswer +"\n" );
                                    tv2.setTextColor(Color.WHITE);
                                    tv2.setTextSize(15);
                                    tv2.setLines(2);
                                    tv2.setSingleLine(false);
                                    tv2.setTypeface(null, Typeface.BOLD);

                                    tv3.setText("\t" + "Actually," + desc +"\n");
                                    tv3.setTextColor(Color.WHITE);
                                    tv3.setTextSize(15);
                                    tv3.setLines(2);
                                    tv3.setSingleLine(false);
                                    tv3.setTypeface(null, Typeface.BOLD);

                                    tv4.setText("\t" + "_____________________________________" );
                                    tv4.setTextColor(Color.WHITE);
                                    tv3.setHorizontallyScrolling(false);
                                    tv4.setTypeface(null, Typeface.BOLD);
                                }
                            } catch (Exception e) {
                                e.printStackTrace();
                            }


                tv1.setLayoutParams(new TableRow.LayoutParams(0,
                                    android.view.ViewGroup.LayoutParams.WRAP_CONTENT,10));
                tv2.setLayoutParams(new TableRow.LayoutParams(0,
                        android.view.ViewGroup.LayoutParams.WRAP_CONTENT,10));
                tv3.setLayoutParams(new TableRow.LayoutParams(0,
                        android.view.ViewGroup.LayoutParams.WRAP_CONTENT,10));


                    row.addView(tv1);
                    row1.addView(tv2);
                    row2.addView(tv3);
                    row3.addView(tv4);
                    answerTable.addView(row);
                    answerTable.addView(row1);
                    answerTable.addView(row2);
                    answerTable.addView(row3);

                }

But nothing is working perfect. This works for the 3rd textview but not for the 1st one. Don’t know what is happening.

Can anybody tell me what to do.

Update

I do not have any problem with this code except that only tv3 gets proceeded to the next line on large text but not the tv1.
I want tv1, tv2 and tv3 all to be continued in the next line in case of large text

  • 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-30T19:16:50+00:00Added an answer on May 30, 2026 at 7:16 pm

    Finally, I came up with some answer for this. First thing is I kept an integer count to fix how much characters to be fit in a single line. After that count the total no of characters in the string. Then divide the first integer count by total no of characters in the string. Then you will get an integer number. For my required, I added +2 for that integer number. Then set the lines of the textview to finally obtained number.

    Thus, problem solved.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported

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.