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
JSONObjects)

//====================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.setText(description);
description_e.setPadding(0, 3, 0, 1);

// Put the TextView into the row and the row into the table.
description_row.addView(description_e);
results_table.addView(description_row, new TableLayout.LayoutParams(
        LayoutParams.FILL_PARENT,
        LayoutParams.WRAP_CONTENT));
//====================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/
suggestions?

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

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android=" http://schemas.android.com/apk/res/ 
android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:stretchColumns="0"
    android:padding="10sp">
    <TableRow>
        <TextView
                android:id="@+id/showName" />
    </TableRow>
    <TableRow
        android:layout_width="fill_parent">
        <ScrollView
                android:id="@+id/resultsScrollView"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_span="2">
                <TableLayout
                        android:id="@+id/showResults"
                        android:layout_width="fill_parent"
                        android:layout_height="wrap_content">
                </TableLayout>
        </ScrollView>
        </TableRow>
</TableLayout>

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



Other Threads

1. Want a dialog

Hi Folks,

I am writing a app on android. I want a dialog to be displayed at the
bottom of the screen which will contain some buttons.

May I know which class i should use to write this dialog.

Can i use showDialog()? if yes, how can i make it display at the
bottom of the screen?

Regards,
Manju

--~--~---------~--~----~------------~-------~--~----~

2. G1 Developer Version UMTS Band / Frequencies?

I've been trying to find the technical specifications of the G1
developer version, to no avail. Is the hardware the same as the T-
Mobile G1, i.e. UMTS band IV only, i.e. no 3G with anyone but T-
Mobile? Will there be a version that also has bands I or II?

--~--~---------~--~----~------------~-------~--~----~

3. vertical scrollbar +code without using xml file.

4. Innovation on Mobile Applications

5. How to create grey menu icons?

6. I am still looking for strong mobile device Android Developers

7. Interaction between java layer and native