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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:11:41+00:00 2026-05-16T22:11:41+00:00

I am desperately trying to set TextView attributes of cells within a table programmatically

  • 0

I am desperately trying to set TextView attributes of cells within a table programmatically but can’t get this to work! Whenever I set layout properties, the field will simply not appear (but not give any error or exception). I boilded this down to this simple example:

package mmo.application.listpro;

import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

public class Test extends Activity
{
    @Override
    public void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        TableLayout table = new TableLayout(this);
        TableRow row = new TableRow(this);
        for (String label: new String[] {"field1", "field2", "field3"}) {
            TextView tv = new TextView(this);
            tv.setText(label);
//          LinearLayout.LayoutParams lp = 
//              new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, 
//                                            LinearLayout.LayoutParams.WRAP_CONTENT);
//          lp.setMargins(2, 2, 2, 2);  // left/top/right/bottom
//          tv.setLayoutParams(lp);
            row.addView(tv);
        }
        table.addView(row);
        setContentView(table);
    }
}

This will show three fields, but when you uncomment the five commented line, then NOTHING will appear. Why is that so? Why does setting layout parameters cause my TextView’s to not appear? I’m stuck! What am I missing?

Michael

PS.: here’s the manifest, if some kind soul quickly wants to try this out:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="mmo.application.listpro" android:versionCode="1" android:versionName="Development">
    <application 
        android:icon="@drawable/icon" 
        android:label="@string/app_name"
        android:debuggable="true">
        <activity
            android:label="test" 
            android:name=".Test"
            android:screenOrientation="portrait">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
    <uses-sdk android:targetSdkVersion="8" android:minSdkVersion="8" />
</manifest> 
  • 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-16T22:11:42+00:00Added an answer on May 16, 2026 at 10:11 pm

    TableRow always enforces those values to be respectively MATCH_PARENT and WRAP_CONTENT. So you just need to create default TableRow.LayoutParams, set margins and apply it to the TextView.

    TableRow.LayoutParams lp = new TableRow.LayoutParams();
    lp.setMargins(2, 2, 2, 2);
    row.addView(tv, lp);;

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

Sidebar

Related Questions

I've been trying desperately to get my application (15 C# dlls and 1 C++/CLI
I am not familiar with this website but I am desperately seeking help with
I am trying desperately to create a final table for a production envirnment, however
I'm desperately hoping someone can assist me with this error. Admittedly, I'm a novice
I'm desperately trying to connect controls of NSViews which will reside in a NSCollectionView
I've been desperately trying for about the last week to figure out whatever my
I am desperate with this issue, I set all the permissions correctly (I think),
currently I'm desperately trying to write german umlauts, read from the console, into a
I'm really desperate on this one. I'm trying to make a Framework which you
I have been at this for hours and MUST get this working! It is

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.