setLayoutParams on a TextView prevents TextView from being displayed

by Stu » Sun, 09 Aug 2009 04:52:57 GMT

Sponsored Links
 I'm populating a TableLayout with TableRows containing a TextView
each. I want the TextViews to FILL_PARENT width and WRAP_CONTENT on
the height.

If I don't specify any LayoutParams for the TextView then it shows up
in the emulator all on one line going off the screen on the right.

If I specify some LayoutParams like the ones below then absolutely no
text shows up whatsoever:

description_element.setLayoutParams(new LayoutParams
(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

I'll paste the relevant code (it gets looped over for a number of

//====================CODE BEGINS HERE
// Create a new TableRow element.
TableRow description_row = new TableRow(this);
description_row.setLayoutParams(new LayoutParams
(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

// Create the new textview for the list and style it.
TextView description_e = new TextView(this);
description_e.setLayoutParams(new LayoutParams
(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
description_e.setPadding(0, 3, 0, 1);

// Put the TextView into the row and the row into the table.
results_table.addView(description_row, new TableLayout.LayoutParams(
//====================CODE ENDS HERE

That code results in the none of the TextViews showing up.

Commenting the descripton_e.setLayoutParams line results in single-
line TextViews that overshoot the screen width.

Adding something like description_e.setWidth(240) results in the
TextView being multiple lines, but obviously at a fixed width, which
isn't really much use to me.

Has anyone encountered this before, or does anyone have any ideas/

I'll post my layout file below in case that has anything to do with

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android=" 
                android:id="@+id/showName" />

Any help or suggestions will be thankfully received as this is driving
me crazy!

Other Threads

1. Why we need to do static compilation?

 I was working on Freescale iMX31 board, I ported android  and it was
working fine , but when it came to integration of WiFi & Bluetooth, android
forum recommended me to do static compilation for porting over android !

 Can I know why some drivers have to be statically compiled before it is
ported over android?
 It was not the case with other drivers which when integrated with android,
they worked perfectly well like serial port, usb etc..

Any info on this would be appreciated.

Best Regards,
Rajesh N


2. Needs info about vendor who makes OEM handset and support Android

Hi everybody, I need info about vendor who makes OEM handset and ready
to using with Android OS especially origin countries from China or
Taiwan. I am looking for OEM product that support for Android with
QWERTY keyboard and support for internet mobile connections
(GPRS/HSDPA). If you have information or if you already as vendor from
your product please contact me. Thanks.



3. How to run all test cases on Android emulator or devices?

4. IOException from RandomAccessFile ?

5. Battery Status and Signal Strength Acheivement

6. How to listen for any change in the contact database

7. contact listener