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

The Archive Base Latest Questions

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

I have an empty LinearLayout , and I need to add a dynamic number

  • 0

I have an empty LinearLayout, and I need to add a dynamic number of TextViews to it. However when I use the code below, only the first TextView is shown:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    String[] listofnumbers = new String[1000];
    for ( int i = 0 ; i < 1000 ; ++i )  {
        listofnumbers[i] = "null";
    }

    Context context = getBaseContext();

    String text = null;

    Uri uri = Uri.parse("content://sms");
    Cursor cursor = context.getContentResolver().query(uri, null, null, null, null);

    String[] columnNames = cursor.getColumnNames();
    LinearLayout lv = new LinearLayout(context);
    LinearLayout.LayoutParams textViewParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, dip(48));

    boolean v = true;
    while (cursor.moveToNext()) 
    {
        String numberString = (cursor.getString( cursor.getColumnIndexOrThrow("address") ) ).replace(" ", "");

        int i = 0;
        boolean numberNotPresent = true;
        for (  ; listofnumbers[i] != "null" ; ++i ) {
            if ( numberString.equals(listofnumbers[i])  )   {
                numberNotPresent = false;
            }
        }
        if ( numberNotPresent == true ) {
            text = (CharSequence) "From: " + cursor.getString(cursor.getColumnIndexOrThrow("address")) + ": " + cursor.getString(cursor.getColumnIndexOrThrow("body"));
            listofnumbers[i] = numberString;
            TextView tv = new TextView(this);
            tv.setText(text);
            tv.setLayoutParams(textViewParams);
            lv.addView( tv );
        }
    }
    setContentView(lv);
}

Where have I gone wrong?

  • 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-31T19:27:32+00:00Added an answer on May 31, 2026 at 7:27 pm

    try to change these two lines:

    LinearLayout lv = new LinearLayout(context);
        LinearLayout.LayoutParams textViewParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, dip(48));
    

    with these:

    LinearLayout lv = new LinearLayout(context);
            lv.setOrientation(LinearLayout.VERTICAL);
            LinearLayout.LayoutParams textViewParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    

    basically you need to set the orientation for the lv LinearLayout to vertical as the default one is horizontal.

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

Sidebar

Related Questions

I have an empty JTable, absolutely nothing in it. I need to dynamically generate
I have an empty TextView set for my ListView . When there is no
If I have an empty tag: <tag/> How can I add text so that
I have following code for main layout: <?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
H have multiple TextViews inside an LinearLayout . Now I want to delete this
So how do I add that it should not have empty field in this
If interfaces have empty methods (implicit abstract method) then what is its use? Why
i have created a vc++ console application i need to add .net assembly references.
I have this code View item = View.inflate(context, R.layout.item_layout, null); LinearLayout.LayoutParams params = new
I am generating an Excel file through MATLAB and I have empty cells in

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.